From 6ba36f553ad48e8faff5d8d4428be1d946044d6a Mon Sep 17 00:00:00 2001 From: Elliot Winkler Date: Thu, 9 Nov 2023 13:35:24 -0700 Subject: [PATCH] Align types with @metamask/eth-json-rpc-provider Currently, passing an instance of SafeEventEmitterProvider to the EthQuery constructor produces a type error. This is happening because the `Provider` type that this package defines allows the `params` property of the JSON-RPC request object to be anything, whereas in the SafeEventEmitterProvider interface, it has to be JSON-compatible. In other words, the provider that this package expects isn't compliant with a "proper" provider. To fix this, this commit manually copies the `Json` and `JsonRpcParams` types from `@metamask/utils` to avoid a direct dependency. This is a temporary solution to prevent this type error from spreading within the `core` codebase. We will investigate a more overarching solution later. --- index.d.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index fd2c7a1..39017a7 100644 --- a/index.d.ts +++ b/index.d.ts @@ -10,6 +10,16 @@ declare module '@metamask/eth-query' { | symbol | undefined; + type Json = + | null + | boolean + | number + | string + | Json[] + | { [prop: string]: Json }; + + type JsonRpcParams = Json[] | Record; + type ProviderSendAsyncResponse = { error?: { message: string }; result?: Result; @@ -21,13 +31,13 @@ declare module '@metamask/eth-query' { ) => void; type Provider = { - sendAsync( + sendAsync( payload: SendAsyncPayload, callback: ProviderSendAsyncCallback, ): void; }; - type SendAsyncPayload = { + type SendAsyncPayload = { id: number; jsonrpc: '2.0'; method: string; @@ -43,7 +53,7 @@ declare module '@metamask/eth-query' { export default class EthQuery { constructor(provider: Provider); - sendAsync( + sendAsync( opts: Partial>, callback: SendAsyncCallback, ): void;