core
core copied to clipboard
Fix middleware functions with implicit, return type-only generic parameters
Motivation
- Middleware functions in
eth-json-rpc-middleware,eth-json-rpc-engine,eth-json-rpc-infuraare "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-docsTypeScript style-guide entry- [ ] Initial notes added here: https://github.com/MetaMask/contributor-docs/issues/69#issuecomment-1910430960
- [ ] Look into adding eslint rules for avoiding return type-only generics.