91

How to fix "Property 'ethereum' does not exist on type 'Window & typeof...

 2 years ago
source link: https://dev.to/nmurgor/how-to-fix-property-ethereum-does-not-exist-on-type-window-typeof-globalthists2339-42dh
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Nmurgor

Posted on Dec 18

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

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

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 https://naftalimurgor.netlify.com


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK