DEV Community

Naftali Murgor
Naftali Murgor

Posted on

How to fix "Property 'ethereum' does not exist on type 'Window & typeof globalThis'.ts(2339)"


When working with MetaMask APIs, you might encounter this warning: "Property 'ethereum' does not exist on type 'Window & typeof globalThis'.ts(2339)" when accessing window.ethereum in a TypeScript project. MetaMask injects a global API into websites visited by its users at window.ethereum

a code snippet screenshot

To fix this warning, and corresponding compile error, add this declaration at the top level of your file, after imports.

declare var window: any
Enter fullscreen mode Exit fullscreen mode

Note, this is not the best fix as this temporarily fixes the warning by telling the TypeScript compiler to treat window as of type any hence ignore any warnings.

This sacrifices also any IntelliSense and auto-completion provided by code editor on the window object.

This article was originally published at

Top comments (2)

sheriff0613 profile image

I have met the same issue.
When I typed above code to my file and met the another issue said "Subsequent variable declarations must have the same type. Variable 'window' must be of type 'Window & typeof globalThis', but here has type 'any'.ts(2403)".
Could you help me with solving this issue?

naftalimurgor profile image
Naftali Murgor

Please share a github or codepen so I can have a look