Chapter 8: html-fund-me-fcc | TypeScript compiliation error for window.ethereum
#614
-
I had just started the Chapter 8. However I am using if (typeof window.ethereum !== "undefined") {
console.log(`You are good to go`);
} else {
console.log(`Please install MetaMask to continue`);
} error error TS2339: Property 'ethereum' does not exist on type 'Window & typeof globalThis'. Not sure how to type cast a |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You can use Or, interface Window {
ethereum: any
} This should fix the type check issue. Another way around would be, to declare the whole declare var window: any The above may or may not disable your IntelliSense for the |
Beta Was this translation helpful? Give feedback.
You can use
(window as any).ethereum
to get around the type check.Or,
In your root folder of the project, you can create a new file called
global.d.ts
and there define theethereum
type like the below code -This should fix the type check issue.
Another way around would be, to declare the whole
window
object asany
at the beginning of your index.The above may or may not disable your IntelliSense for the
window
object.