File tree Expand file tree Collapse file tree
packages/eth-json-rpc-provider/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -24,6 +24,10 @@ export function providerFromMiddleware<
2424 Result extends Json ,
2525> ( middleware : LegacyJsonRpcMiddleware < Params , Result > ) : InternalProvider {
2626 return providerFromMiddlewareV2 (
27+ // This function is generic on the Params and Result types to match the legacy JsonRpcMiddleware type.
28+ // However, since the V2 JsonRpcMiddleware type is not generic on the Params, we need to elide this
29+ // parameter by upcasting the request type to JsonRpcRequest, or we get an error due to contravariance
30+ // since JsonRpcRequest<Params> is not assignable to JsonRpcRequest.
2731 asV2Middleware ( middleware ) as JsonRpcMiddleware < JsonRpcRequest > ,
2832 ) ;
2933}
@@ -44,6 +48,9 @@ export function providerFromMiddlewareV2<
4448> ( middleware : Middleware ) : InternalProvider {
4549 return new InternalProvider ( {
4650 engine : JsonRpcEngineV2 . create ( {
51+ // This function is generic in order to accept middleware functions with narrower types than
52+ // the plain JsonRpcMiddleware<JsonRpcRequest> type. However, since InternalProvider is non-generic,
53+ // we need to upcast the middleware to avoid a type error.
4754 middleware : [ middleware as JsonRpcMiddleware < JsonRpcRequest > ] ,
4855 } ) ,
4956 } ) ;
You can’t perform that action at this time.
0 commit comments