node-sdk
node-sdk copied to clipboard
Auto-complete path parameters
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:
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"]