模板字面量类型

// css 的 margin、padding 属性

type Direction = 'left' | 'right' | 'top' | 'bottom';
type CssPadding = `padding-${Direction}`;
type MarginPadding = `margin-${Direction}`;
// 实用例子
type EventName<T extends string> = `${T}Changed`;
type Concat<S1 extends string, S2 extends string> = `${S1}-${S2}`;
type ToString<T extends string | number | boolean | bigint> = `${T}`;
type T0 = EventName<'foo'>; // 'fooChanged'
type T1 = Concat<'Hello', 'World'>; // 'Hello-World'
type T2 = ToString<'阿宝哥' | 666 | true | -1234n>; // "阿宝哥" | "true" | "666" | "-1234"
type T3 = EventName<'foo' | 'bar' | 'baz'>;
// "fooChanged" | "barChanged" | "bazChanged"
type T4 = Concat<'top' | 'bottom', 'left' | 'right'>;
// "top-left" | "top-right" | "bottom-left" | "bottom-right"