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 …


This content originally appeared on DEV Community and was authored by Nmurgor

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

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

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


This content originally appeared on DEV Community and was authored by Nmurgor


Print Share Comment Cite Upload Translate Updates
APA

Nmurgor | Sciencx (2021-12-18T14:50:31+00:00) How to fix “Property ‘ethereum’ does not exist on type ‘Window & typeof globalThis’.ts(2339)”. Retrieved from https://www.scien.cx/2021/12/18/how-to-fix-property-ethereum-does-not-exist-on-type-window-typeof-globalthis-ts2339/

MLA
" » How to fix “Property ‘ethereum’ does not exist on type ‘Window & typeof globalThis’.ts(2339)”." Nmurgor | Sciencx - Saturday December 18, 2021, https://www.scien.cx/2021/12/18/how-to-fix-property-ethereum-does-not-exist-on-type-window-typeof-globalthis-ts2339/
HARVARD
Nmurgor | Sciencx Saturday December 18, 2021 » How to fix “Property ‘ethereum’ does not exist on type ‘Window & typeof globalThis’.ts(2339)”., viewed ,<https://www.scien.cx/2021/12/18/how-to-fix-property-ethereum-does-not-exist-on-type-window-typeof-globalthis-ts2339/>
VANCOUVER
Nmurgor | Sciencx - » How to fix “Property ‘ethereum’ does not exist on type ‘Window & typeof globalThis’.ts(2339)”. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/12/18/how-to-fix-property-ethereum-does-not-exist-on-type-window-typeof-globalthis-ts2339/
CHICAGO
" » How to fix “Property ‘ethereum’ does not exist on type ‘Window & typeof globalThis’.ts(2339)”." Nmurgor | Sciencx - Accessed . https://www.scien.cx/2021/12/18/how-to-fix-property-ethereum-does-not-exist-on-type-window-typeof-globalthis-ts2339/
IEEE
" » How to fix “Property ‘ethereum’ does not exist on type ‘Window & typeof globalThis’.ts(2339)”." Nmurgor | Sciencx [Online]. Available: https://www.scien.cx/2021/12/18/how-to-fix-property-ethereum-does-not-exist-on-type-window-typeof-globalthis-ts2339/. [Accessed: ]
rf:citation
» How to fix “Property ‘ethereum’ does not exist on type ‘Window & typeof globalThis’.ts(2339)” | Nmurgor | Sciencx | https://www.scien.cx/2021/12/18/how-to-fix-property-ethereum-does-not-exist-on-type-window-typeof-globalthis-ts2339/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.