Open
Description
Motivation
- Middleware functions in
eth-json-rpc-middleware
,eth-json-rpc-engine
,eth-json-rpc-infura
are "return type-only" generics with implicit generic parameters. This is a discouraged pattern. - Redefining the functions to expose the generic parameters that are implicitly hard-coded into their return type would make them less brittle to future typing updates.
- Example error: "
JsonRpcMiddleware<unknown, unknown>
is not assignable to parameter of typeJsonRpcMiddleware<JsonRpcParams, Json>
"
- Example error: "
// before
function createExampleMiddleware(exampleParam): JsonRpcMiddleware<JsonRpcParams, Json>
// after
function createExampleMiddleware<
Params extends JsonRpcParams = JsonRpcParmas,
Result extends Json = Json
>(exampleParam): JsonRpcMiddleware<Params, Result>
Tasks
- Compile list of functions and types to be fixed.
- Expose the return type generic params in the outer type/function.
- Assign default arguments to provide a consistent interface and minimize disruption.
- Add
contributor-docs
TypeScript style-guide entry- Initial notes added here: Complete TypeScript guidelines contributor-docs#69 (comment)
- Look into adding eslint rules for avoiding return type-only generics.