Skip to content

Conversation

@harrysolovay
Copy link

Throughout the codebase, type param ordering places P (the parsed param object, inferred from the route path literal) before S (library-consumer-declared state). This is ordering is not preferable, as it does not allow one to explicitly type S while still inferring P.

For instance, let's consider the following example:

const SOME_PATH = "/x/:hi/:there"
const handler: RouterMiddleware<typeof SOME_PATH> = (ctx) => {
  ctx.params // { hi: string; there: string; }
}

If I want to specify a type for state, I'd need to do the following:

- const handler: RouterMiddleware<typeof SOME_PATH> = (ctx) => {
+ const handler: RouterMiddleware<typeof SOME_PATH, RouteParams<typeof SOME_PATH>, MyStateType> = (ctx) => {}

By reversing the type param order, we can simplify.

- const handler: RouterMiddleware<typeof SOME_PATH> = (ctx) => {
+ const handler: RouterMiddleware<typeof SOME_PATH, MyStateType> = (ctx) => {}

Please let me know if this change is desirable and––if so––what else needs to come into place. I needed to disable a few type type tests which were failing (would be great to hear maintainer thoughts on those failures).

@CLAassistant
Copy link

CLAassistant commented Dec 18, 2022

CLA assistant check
All committers have signed the CLA.

@denizdogan
Copy link

Could someone please take a look at this PR?

@harrysolovay
Copy link
Author

Kindly pinging @kitsonk for thoughts/guidance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants