How to fix "Property 'ethereum' does not exist on type 'Window & typeof globalThis'.ts(2339)"
Naftali Murgor
Posted on December 18, 2021
Introduction
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
To fix this warning, and corresponding compile error, add this declaration at the top level of your file, after imports.
declare var window: any
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 https://naftalimurgor.netlify.com
Posted on December 18, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
May 24, 2023
December 18, 2021