RecipesChapter 12: Type Development Strategies

Naming Generics

Recipe 12.8 from The TypeScript Cookbook

type ParseRouteParameters<TRoute> =
  Route extends `${string}/:${infer TParam}/${infer TRest}` ?
    { [TEntry in TParam | keyof ParseRouteParameters<`/${TRest}`>]: string } :
  Route extends `${string}/:${infer TParam}` ?
    { [TEntry in TParam]: string } : {}
Open in TypeScript Playground →