DEV Community

Naftali Murgor
Naftali Murgor

Posted on

6 2

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

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

SurveyJS custom survey software

Build Your Own Forms without Manual Coding

SurveyJS UI libraries let you build a JSON-based form management system that integrates with any backend, giving you full control over your data with no user limits. Includes support for custom question types, skip logic, an integrated CSS editor, PDF export, real-time analytics, and more.

Learn more

Top comments (2)

Collapse
 
master_shifu profile image
sheriff0613

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?

Collapse
 
naftalimurgor profile image
Naftali Murgor

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

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay