You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix provider type errors in NetworkController and its downstream packages #1823
ProxyWithAccessibleTarget<SafeEventEmitterProvider> (@metamask/network-controller) vs. Provider (@metamask/eth-query)
error TS2345: Argumentoftype 'ProxyWithAccessibleTarget<SafeEventEmitterProvider>' is not assignable to parameter of type 'Provider<JsonRpcParams,Json>'.Typesofproperty 'sendAsync' areincompatible.Type'(req: JsonRpcRequest<JsonRpcParams>, callback: (error: unknown, providerRes?: any) => void) => void'isnotassignabletotype '<Params,Result>(payload: SendAsyncPayload<Params>,callback: ProviderSendAsyncCallback<Result>)=>void'.Typesofparameters 'req' and'payload'areincompatible.Type 'SendAsyncPayload<Params>' is not assignable to type 'JsonRpcRequest<JsonRpcParams>'.
changed the title [-]Fix provider, middleware type errors in NetworkController and downstream packages[/-][+]Fix provider type errors in `NetworkController` and its downstream packages[/+]on Nov 8, 2023
@mcmire I'm still seeing the following error in this PR MetaMask/smart-transactions-controller#237, even after updating @metamask/eth-query and @metamask/network-controller to the latest versions.
src/SmartTransactionsController.ts:334:31-errorTS2345: Argumentoftype 'ProxyWithAccessibleTarget<SafeEventEmitterProvider>' is not assignable to parameter of type 'Provider'.Typesofproperty'sendAsync'areincompatible.Type'(req: JsonRpcRequest<JsonRpcParams>, callback: (error: unknown, providerRes?: any) => void) => void'isnotassignabletotype'<Params, Result>(payload: SendAsyncPayload<Params>, callback: ProviderSendAsyncCallback<Result>) => void'.Typesofparameters'req'and'payload'areincompatible.Type 'SendAsyncPayload<Params>' is not assignable to type 'JsonRpcRequest<JsonRpcParams>'.Type 'SendAsyncPayload<Params>' is not assignable to type '{params?: ((Record<string,Json>|Json[])&ExactOptionalGuard)|undefined; id: string|number|null; method: string; jsonrpc: "2.0";}'.
Typesofproperty'params'areincompatible.Type'Params'isnotassignabletotype'((Record<string, Json> | Json[]) & ExactOptionalGuard) | undefined'.Type'Params'isnotassignabletotype'Json[] & ExactOptionalGuard'.Type'Params'isnotassignabletotype'Json[]'.334ethQuery=newEthQuery(networkClient.provider);
I think we need to make the following updates to SafeEventEmitterProvider in @metamask/eth-json-rpc-provider to make it align with the @metamask/utils updates.
diff --git a/packages/eth-json-rpc-provider/src/safe-event-emitter-provider.ts b/packages/eth-json-rpc-provider/src/safe-event-emitter-provider.ts
index fbf2db3ae..db9298cf0 100644
--- a/packages/eth-json-rpc-provider/src/safe-event-emitter-provider.ts+++ b/packages/eth-json-rpc-provider/src/safe-event-emitter-provider.ts@@ -1,6 +1,11 @@
import type { JsonRpcEngine } from '@metamask/json-rpc-engine';
import SafeEventEmitter from '@metamask/safe-event-emitter';
-import type { JsonRpcRequest } from '@metamask/utils';+import type {+ Json,+ JsonRpcParams,+ JsonRpcRequest,+ JsonRpcResponse,+} from '@metamask/utils';
/**
* An Ethereum provider.
@@ -34,9 +39,12 @@ export class SafeEventEmitterProvider extends SafeEventEmitter {
* @param req - The request to send.
* @param callback - A function that is called upon the success or failure of the request.
*/
- sendAsync = (- req: JsonRpcRequest,- callback: (error: unknown, providerRes?: any) => void,+ sendAsync = <+ Params extends JsonRpcParams = JsonRpcParams,+ Result extends Json = Json,+ >(+ req: JsonRpcRequest<Params>,+ callback: (error: unknown, providerRes?: JsonRpcResponse<Result>) => void,
) => {
this.#engine.handle(req, callback);
};
@@ -51,9 +59,12 @@ export class SafeEventEmitterProvider extends SafeEventEmitter {
* @param req - The request to send.
* @param callback - A function that is called upon the success or failure of the request.
*/
- send = (- req: JsonRpcRequest,- callback: (error: unknown, providerRes?: any) => void,+ send = <+ Params extends JsonRpcParams = JsonRpcParams,+ Result extends Json = Json,+ >(+ req: JsonRpcRequest<Params>,+ callback: (error: unknown, providerRes?: JsonRpcResponse<Result>) => void,
) => {
if (typeof callback !== 'function') {
throw new Error('Must provide callback to "send" method.');
The above is caused by the @metamask/eth-query version bump in controller-utils (#2028) not being released yet. The issue will be resolved by the next release that includes the unreleased changes in all of @metamask/eth-query's downstream packages in core.
Activity
[-]Fix provider, middleware type errors in NetworkController and downstream packages[/-][+]Fix provider type errors in `NetworkController` and its downstream packages[/+]Fix misaligned mock eth query types in controller tests (#2037)
mcmire commentedon Nov 20, 2023
What's left on this ticket?
MajorLift commentedon Nov 20, 2023
@mcmire I'm still seeing the following error in this PR MetaMask/smart-transactions-controller#237, even after updating
@metamask/eth-queryand@metamask/network-controllerto the latest versions.I think we need to make the following updates to
SafeEventEmitterProviderin@metamask/eth-json-rpc-providerto make it align with the@metamask/utilsupdates.MajorLift commentedon Nov 22, 2023
The above is caused by the
@metamask/eth-queryversion bump incontroller-utils(#2028) not being released yet. The issue will be resolved by the next release that includes the unreleased changes in all of@metamask/eth-query's downstream packages in core.anyusage and reducingasassertions #1971