Slide 42
Slide 42 text
Template Literal Types
type A = PathSplit<'a.b.c'>
// ==> ['a', 'b', 'c']
type PathSplit =
T extends `${infer A}.${infer B}`
? (B extends ''
? [A]
: [A, ...PathSplit])
: [T]
type B = PathJoin<['a','b','c']>
// ==> 'a.b.c'
type PathJoin =
T extends [infer A, ...infer Rest]
? A extends string
? Rest extends []
? A
: Rest extends string[]
? `${A}.${PathJoin}`
: never
: never
: ""
// aͱb.cʹόϥ͢
// [a, ...] ʹ͚ͬͭ͘Δ
// aͱ [b, c] ʹόϥ͢
// `a.${Γ}` ʹ͚ͬͭ͘Δ