Skip to content

Fix middleware functions with implicit, return type-only generic parameters #2010

Open
@MajorLift

Description

@MajorLift

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 type JsonRpcMiddleware<JsonRpcParams, Json>"
// 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
  • Look into adding eslint rules for avoiding return type-only generics.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions