Skip to main content

字符串模板语法

例子:

type WithChanged<T extends string> = `${T}Changed`;
type ToggleChanged = WithChanged<'toggle'>; // 'toggleChanged'

Align 例子:

type VAlign = 'top' | 'center' | 'bottom';
type HAlign = 'left' | 'center' | 'right';
// "top-center" | "top-left" | "top-right" | "center-center" | "center-left" | "center-right" | "bottom-center" | "bottom-left" | "bottom-right"
type Align = `${VAlign}-${HAlign}`;

或者:

type VAlign = 'top' | 'center' | 'bottom';
type HAlign = 'left' | 'center' | 'right';
type Concat<A extends string, B extends string> = `${A}-${B}`;
type Align = Concat<VAlign, HAlign>;