detect-provider icon indicating copy to clipboard operation
detect-provider copied to clipboard

detectEthereumProvider get unknown return

Open dsky1990 opened this issue 4 years ago • 6 comments
trafficstars

detectEthereumProvider get unknown return , it's error in the typescript

dsky1990 avatar Apr 25 '21 11:04 dsky1990

+1

It would be better if it returned EthereumProvider | null

joelamouche avatar May 10 '21 15:05 joelamouche

+1

spb-web avatar Aug 21 '21 16:08 spb-web

Additionally, the EthereumProvider type only contains a single field (isMetaMask). It would be very useful to have full provider typing here!

nharlow89 avatar Sep 30 '21 05:09 nharlow89

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>;

pyoner avatar May 20 '22 08:05 pyoner

This is fixed in #41, but we have yet to release a new version.

mcmire avatar May 20 '22 16:05 mcmire

Still no new version, it is a bit annoying to deal with these types myself

martonlederer avatar Jul 04 '22 10:07 martonlederer

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!

mcmire avatar Oct 05 '22 16:10 mcmire