Categories
TypeScript Answers

How to fix the “TypeScript error: Property ‘X’ does not exist on type ‘Window'” error?

Spread the love

Sometimes, we want to fix the "TypeScript error: Property ‘X’ does not exist on type ‘Window’" error.

In this article, we’ll look at how to fix the "TypeScript error: Property ‘X’ does not exist on type ‘Window’" error.

How to fix the "TypeScript error: Property ‘X’ does not exist on type ‘Window’" error?

To fix the "TypeScript error: Property ‘X’ does not exist on type ‘Window’" error, we add the window property we added into the type definition.

For instance, we write

declare global {
  interface Window {
    FB: any;
  }
}

to declare the Window interface which has the FB property.

Then we can use window.FB in our app without errors by writing

let FB = window.FB;

Conclusion

To fix the "TypeScript error: Property ‘X’ does not exist on type ‘Window’" error, we add the window property we added into the type definition.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *