oak icon indicating copy to clipboard operation
oak copied to clipboard

reverse type param ordering

Open harrysolovay opened this issue 3 years ago • 3 comments

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).

harrysolovay avatar Dec 18 '22 19:12 harrysolovay

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Dec 18 '22 19:12 CLAassistant

Could someone please take a look at this PR?

denizdogan avatar Apr 27 '23 12:04 denizdogan

Kindly pinging @kitsonk for thoughts/guidance.

harrysolovay avatar Jun 13 '23 20:06 harrysolovay