detect-provider
detect-provider copied to clipboard
detectEthereumProvider get unknown return
detectEthereumProvider get unknown return , it's error in the typescript
+1
It would be better if it returned EthereumProvider | null
+1
Additionally, the EthereumProvider type only contains a single field (isMetaMask). It would be very useful to have full provider typing here!
got dist/index.d.ts with Promise<unknown>
interface EthereumProvider {
isMetaMask?: boolean;
}
declare global {
interface Window {
ethereum?: EthereumProvider;
}
}
export = detectEthereumProvider;
/**
* Returns a Promise that resolves to the value of window.ethereum if it is
* set within the given timeout, or null.
* The Promise will not reject, but an error will be thrown if invalid options
* are provided.
*
* @param options - Options bag.
* @param options.mustBeMetaMask - Whether to only look for MetaMask providers.
* Default: false
* @param options.silent - Whether to silence console errors. Does not affect
* thrown errors. Default: false
* @param options.timeout - Milliseconds to wait for 'ethereum#initialized' to
* be dispatched. Default: 3000
* @returns A Promise that resolves with the Provider if it is detected within
* given timeout, otherwise null.
*/
declare function detectEthereumProvider({ mustBeMetaMask, silent, timeout, }?: {
mustBeMetaMask?: boolean | undefined;
silent?: boolean | undefined;
timeout?: number | undefined;
}): Promise<unknown>;
This is fixed in #41, but we have yet to release a new version.
Still no new version, it is a bit annoying to deal with these types myself
2.0.0 is released with proper types to remind you to handle null in your code. Please let us know if you're still having problems and we'll look into it further!