node-sdk icon indicating copy to clipboard operation
node-sdk copied to clipboard

Auto-complete path parameters

Open jyecusch opened this issue 2 years ago • 0 comments

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 avatar Jul 13 '23 00:07 jyecusch