`:${infer Param}/${infer Rest}` ? Param | PathParams<Rest> :
Path extends `:${infer Param}` ? Param :
Path extends `${infer _Prefix}:${infer Rest}` ? PathParams<`:${Rest}`> :
never
type PathArgs<Path extends string> = {
[K in PathParams<Path>]: string
}
const matchPaths = <Context>(userOptions: Partial<Options<Context>> = {}) =>
<P extends string>(paths: {[P]: (context: Context & { params: PathArgs<P> }) => void}) => ...
so e.g. I call matchPaths()({ 'test/:id': context => console.log(context.params.id) })('test/4')
matchPaths({})({ 'test/:id': context => console.log(context.params.id) })('test/4')
Обсуждают сегодня