Type alias StrTemplate<T, S>

StrTemplate<T, S>: T extends `${infer L}%s${infer R}` ? S["length"] extends 0 ? StrTemplate<`${L}${R}`> : StrTemplate<`${L}${S[0]}${R}`, ShiftTuple<S>> : T

字符串模板

Example

type S1 = StrTemplate<'1%s3', ['2']>; // 123
type S2 = StrTemplate<'%s23', ['1']>; // 123
type S3 = StrTemplate<'123', ['1']>; // 123
type SW = StrTemplate<'a%sc%se', ['b', 'd']>; // abcde
type SW2 = StrTemplate<'a%sc%se', ['b', 'd', 'f']>; // abcde
type S5 = StrTemplate<'hell%s worl%s'> // hell worl

Type Parameters

  • T extends string

  • S extends any[] = []