Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please consider adding more complex typing for result groups #130

Open
ghost opened this issue Jul 11, 2024 · 0 comments
Open

Please consider adding more complex typing for result groups #130

ghost opened this issue Jul 11, 2024 · 0 comments

Comments

@ghost
Copy link

ghost commented Jul 11, 2024

Right now the typing for URL pattern component result groups is basically just Record<string, string | undefined>.

However, take a look at this: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/7d182347b9be493cd37ad26a0b7a8285310cc914/types/express-serve-static-core/index.d.ts#L108

You can see it is able to infer the correct params based on a string.

For example:

const pathname = "/about/:name/:age?";

const props = async (groups: RouteParameters<typeof pathname>) => {
  return { name: groups.name };
};

It infers the types perfectly, and works with optional params, and infinite params:

(parameter) groups: {
    name: string;
} & {
    age?: string | undefined;
}

For now I have added this package to my project, but it would be nice if this lib implemented the same typing for groups.

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

No branches or pull requests

0 participants