What's the correct way to avoid Typescript errors with BrowserProvider typings? #4270
-
Hello, I used to work on v5, now I switched to 6 and I have an issue with BrowserProvider types: const provider = new BrowserProvider(
window.ethereum //as Eip1193Provider`
);
const signer = await provider.getSigner(); if I don't add the commented I also use web3React for wallet connection and if I get the signer from the provider that comes from Is there a better way to deal with this problem or the Thanks for your interest! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
@bloodylupin add a global.d.ts file to your root directory and add the following code: import { Eip1193Provider } from "ethers"
declare global {
interface Window {
ethereum: Eip1193Provider
}
} errors should be gone after that. |
Beta Was this translation helpful? Give feedback.
I did try the
const provider = new BrowserProvider(window.ethereum as EIP1193Provider)
but I got even more errors. I have to be honest I have only recently started to use typescript in my projects. This way did what I needed it to do.After a bit of digging, you could try to extend type EthereumProvider type to include the missing properties required by Eip1193Provider.
Note this is just a suggestio…