TypeScript Error: Property 'X' does not exist on type 'Window' in React application
Hello! I'm developing a React application using create-react-app and TypeScript. I have a problem: I'm trying to access the global property `window.myCustomProp`, which I added to the `window` object for integration with a third-party script. Here's my code:
```typescript
// App.tsx
const App: React.FC = () => {
useEffect(() => {
// Set custom property
window.myCustomProp = 'Hello from custom property';
// Try to read it
console.log(window.myCustomProp);
}, []);
return
My App
;
};
```
When compiling, TypeScript throws an error:
```
Property 'myCustomProp' does not exist on type 'Window & typeof globalThis'.
```
I've already tried using `(window as any).myCustomProp`, but it looks like a hack. If No answers yet.
Log in to leave an answer