我想知道是否有一种方法可以将两种类型脚本类型连接起来,例如:
type Size = 'xl' | 'xxl' ...;
let textSize: 'text-' & Size;
// So my type is something like : 'text-xl' | 'text-xxl'
通过使用模板文字类型。
type Size = 'xl' | 'xxl';
type TextSizeType = `text-${Size}`;
TS将TextSizeType
解析为
type TextSizeType = "text-xl" | "text-xxl"
这听起来像你想要的。