Typescript:定义一个可以';我拿不住任何东西
我对这种类型感兴趣(为了验证),这种类型的变量不能有任何赋值。有类型Typescript:定义一个可以';我拿不住任何东西,typescript,Typescript,我对这种类型感兴趣(为了验证),这种类型的变量不能有任何赋值。有类型void,但是这种类型的值可以包含未定义的值,所以这不完全是我要问的 我似乎能够通过不兼容类型的交集重现这种行为: type nothing = true & false; const nothingTrue: nothing = true; // error, true not assignable to false const nothingFalse: nothing = false; // error, fals
void
,但是这种类型的值可以包含未定义的值
,所以这不完全是我要问的
我似乎能够通过不兼容类型的交集重现这种行为:
type nothing = true & false;
const nothingTrue: nothing = true; // error, true not assignable to false
const nothingFalse: nothing = false; // error, false not assignable to true
const nothingUndefined: nothing = undefined; // error, undefined not assignable to true
但这看起来更像是黑客。也许还有更清楚的事情?或者这是正确的方法吗?您要查找的类型是
从不类型。从:
never类型是每种类型的子类型,可分配给每种类型;但是,任何类型都不是never的子类型,也不能指定给never(never本身除外)。即使是任何一个都不能分配给永远
您要查找的类型是never
类型。从:
never类型是每种类型的子类型,可分配给每种类型;但是,任何类型都不是never的子类型,也不能指定给never(never本身除外)。即使是任何一个都不能分配给永远
从不
?刚刚测试-就这样,谢谢。以前使用过这种类型,但理解能力差。抱歉这个愚蠢的问题。从不
?刚刚测试过-就这样,谢谢。以前使用过这种类型,但理解能力差。对不起,我问了个愚蠢的问题。