首页 > 其他分享 >[Typescript] 92. Medium - PathParams

[Typescript] 92. Medium - PathParams

时间:2022-11-09 22:33:31浏览次数:48  
标签:Typescript string Param PathParams Medium Expect 92 infer

type PathParams<S extends string> =
  S extends `/${string}/:${infer Param}/${infer REST}`
    ? Param | PathParams<`/${REST}`>
    : S extends `${string}/:${infer Param}`
    ? Param
    : never;

[
  Expect<Equal<PathParams<"/profile">, never>>,
  Expect<Equal<PathParams<"/profile/:userId">, "userId">>,
  Expect<
    Equal<PathParams<"/profile/:userId/posts/:postId">, "userId" | "postId">
  >,
];

 

标签:Typescript,string,Param,PathParams,Medium,Expect,92,infer
From: https://www.cnblogs.com/Answer1215/p/16875427.html

相关文章