From eaf35ff2ba0437aa20933f65537593561850943e Mon Sep 17 00:00:00 2001 From: Elliot Winkler Date: Wed, 5 Jul 2023 15:56:16 -0600 Subject: [PATCH] Add TypeScript type definitions TypeScript will refuse to build a project that relies on `eth-query`, as it lacks type definitions. We have previously gotten around this in the extension and in `core` by supplying those type definitions directly in the project itself, but this is causing issues especially for the Snaps team, who now wish to use `@metamask/controller-utils`, which names `eth-query` as a dependency. This commit copies the type definitions from the `core` monorepo into this repo. They were previously copied from the extension, so they have been battle-tested pretty well now. --- index.d.ts | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..77f270c --- /dev/null +++ b/index.d.ts @@ -0,0 +1,53 @@ +declare module 'eth-query' { + // What it says on the tin. We omit `null`, as that value is used for a + // successful response to indicate a lack of an error. + type EverythingButNull = + | string + | number + | boolean + // eslint-disable-next-line @typescript-eslint/ban-types + | object + | symbol + | undefined; + + type ProviderSendAsyncResponse = { + error?: { message: string }; + result?: Result; + }; + + type ProviderSendAsyncCallback = ( + error: unknown, + response: ProviderSendAsyncResponse, + ) => void; + + type Provider = { + sendAsync( + payload: SendAsyncPayload, + callback: ProviderSendAsyncCallback, + ): void; + }; + + type SendAsyncPayload = { + id: number; + jsonrpc: '2.0'; + method: string; + params: Params; + }; + + type SendAsyncCallback = ( + ...args: + | [error: EverythingButNull, result: undefined] + | [error: null, result: Result] + ) => void; + + export default class EthQuery { + constructor(provider: Provider); + + sendAsync( + opts: Partial>, + callback: SendAsyncCallback, + ): void; + + [method: string]: (...args: any[]) => void; + } +}