-
-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix provider type errors in NetworkController
and its downstream packages
#1823
Comments
NetworkController
and its downstream packages
## Explanation Fixes `// @ts-expect-error Mock eth query does not fulfill type requirements` annotations throughout core repo. ## References - Builds upon - MetaMask/eth-query#21 - #2028 - Related #1823 - Closes #2036 ## Changelog N/A ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've highlighted breaking changes using the "BREAKING" category above as appropriate
What's left on this ticket? |
@mcmire I'm still seeing the following error in this PR MetaMask/smart-transactions-controller#237, even after updating src/SmartTransactionsController.ts:334:31 - error TS2345: Argument of type 'ProxyWithAccessibleTarget<SafeEventEmitterProvider>' is not assignable to parameter of type 'Provider'.
Types of property 'sendAsync' are incompatible.
Type '(req: JsonRpcRequest<JsonRpcParams>, callback: (error: unknown, providerRes?: any) => void) => void' is not assignable to type '<Params, Result>(payload: SendAsyncPayload<Params>, callback: ProviderSendAsyncCallback<Result>) => void'.
Types of parameters 'req' and 'payload' are incompatible.
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"; }'.
Types of property 'params' are incompatible.
Type 'Params' is not assignable to type '((Record<string, Json> | Json[]) & ExactOptionalGuard) | undefined'.
Type 'Params' is not assignable to type 'Json[] & ExactOptionalGuard'.
Type 'Params' is not assignable to type 'Json[]'.
334 ethQuery = new EthQuery(networkClient.provider); I think we need to make the following updates to 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 |
Explanation
@ts-expect-error TODO:
annotations in deps: Bump@metamask/{eth-json-rpc-provider,rpc-errors}
#1653.network-controller
,selected-network-controller
,transaction-controller
,gas-fee-controller
Tasks
Provider type alignment
ProxyWithAccessibleTarget<SafeEventEmitterProvider>
(@metamask/network-controller
) vs.Provider
(@metamask/eth-query
)SafeEventEmitterProvider
ProviderProxy
FakeProvider
References
The text was updated successfully, but these errors were encountered: