Skip to content

reverse type param ordering - #579

Draft
harrysolovay wants to merge 2 commits into
oakserver:mainfrom
harrysolovay:main
Draft

harrysolovay wants to merge 2 commits into
oakserver:mainfrom
harrysolovay:main

Conversation

@harrysolovay

Copy link
Copy Markdown

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

CLAassistant commented Dec 18, 2022 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@denizdogan

Copy link
Copy Markdown

Could someone please take a look at this PR?

@harrysolovay

Copy link
Copy Markdown
Author

Kindly pinging @kitsonk for thoughts/guidance.

This branch has not been deployed

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

Labels

None yet

3 participants