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.