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

Auto-complete path parameters #199

Open
jyecusch opened this issue Jul 13, 2023 · 0 comments
Open

Auto-complete path parameters #199

jyecusch opened this issue Jul 13, 2023 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@jyecusch
Copy link
Member

Feature Request

Suggestion

Using Express.js again with TypeScript we noticed it's able to auto-complete the path param property names on requests based on the defined route.

Example:
path-param-suggestion

This appears to be achieved using type definitions like the example below from @types/express.

// prettier-ignore
export type RouteParameters<Route extends string> = string extends Route
    ? ParamsDictionary
    : Route extends `${string}(${string}`
        ? ParamsDictionary //TODO: handling for regex parameters
        : Route extends `${string}:${infer Rest}`
            ? (
            GetRouteParameter<Rest> extends never
                ? ParamsDictionary
                : GetRouteParameter<Rest> extends `${infer ParamName}?`
                    ? { [P in ParamName]?: string }
                    : { [P in GetRouteParameter<Rest>]: string }
            ) &
            (Rest extends `${GetRouteParameter<Rest>}${infer Next}`
                ? RouteParameters<Next> : unknown)
            : {};

Let's try to implement something equivalent in our ctx.req object.

Value

Reduce typos and improve the type safety of the params object.

Alternatives

The current solution of retrieving values like this ctx.req.params["pathparam"]

@jyecusch jyecusch added the enhancement New feature or request label Jul 13, 2023
@HomelessDinosaur HomelessDinosaur self-assigned this Dec 13, 2023
@jyecusch jyecusch added the good first issue Good for newcomers label Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants