[Typescript] 105. Medium - Placeholder

type Placeholder<T extends string> = T extends `${string}{${infer P}}${infer REST}`
  ? P | Placeholder<REST>
  : never;

declare function format<S extends string>(template: S, args: Record<Placeholder<S>, unknown>): string

let text = format('Name: {name}, Age: {age}', {name: 'Homer', age: 42})

posted @ 2022-11-16 14:48  Zhentiw  阅读(9)  评论(0编辑  收藏  举报