[Typescript] Execrise: Possible routes type

const routes = {
  user: ["get-user", "get-all-users"],
  comment: ["get-comment", "get-all-comments"]
} as const
type Routes = typeof routes

type PossibleUrl = {
  [K in keyof Routes]: `/${K}/${Routes[K][number]}`
}[keyof Routes]

type Example = Record<PossibleUrl, {}>

posted @ 2024-01-22 02:52  Zhentiw  阅读(4)  评论(0编辑  收藏  举报