never类型用于表示不应该存在或无法达到预期的状态
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| type A = string & number
type B = void | number | never
function error(message:string):never { throw new Error(message) }
function loop():never { while(true) {} }
type kun = "唱" | "跳" | "rap" | "篮球" function kun(value:kun) { switch(value) { case "唱": console.log("只因你实在是太美") break case "跳": console.log("再多一眼看一眼就会爆炸") break case "rap": console.log("第一次呀变成这样的我") break case "篮球": console.log("你要我怎么去否认") break default: console.log("You're not kun, who are you???") const error:never = value break } }
|