ts如何定义”不等于xx“类型

新手上路,请多包涵

假如有一个类型:

type Text1 = "a" | "b";

那么如何定义一个string,不能是Text?类似下面这种:

type Text2 = Exclude<string, Text1>;

// 这里希望报错,但是并没有
const a: Text2 = "a";
阅读 2.8k
1 个回答

typescript 目前不支持,因为 string 对于 Text1 不是可枚举的

推荐问题