Open rimo030 opened 5 months ago
처음에는 아래와 같이 작성했었다.
type Format<T extends string> = T extends `${any}%${infer F}${infer R}`
? F extends 's'
? (s1 :string) => Format<R>
: F extends 'd'
? (d1 :number) => Format<R>
: Format<R>
: string
다음과 같이 포맷타입 분리해 작성하면 재사용성을 높힐수 있다.
type FormatType = {
s : string,
d : number
// ...
}
type Format<T extends string> = T extends `${any}%${infer F}${infer R}`
? F extends keyof FormatType
? (x: FormatType[F]) => Format<R>
: Format<R>
: string