// 类型别名
let a: 1 | 2 | 3 | 4 | 5;
let b:1 | 2 | 3 | 4 | 5;
// 上面这样写麻烦 可以给类型起个别名
type myType = 1 | 2 | 3 | 4 | 5;
let c: myType;
let d: myType;
c = 1;
// 这里就报错
d = 6;
// 类型别名
let a: 1 | 2 | 3 | 4 | 5;
let b:1 | 2 | 3 | 4 | 5;
// 上面这样写麻烦 可以给类型起个别名
type myType = 1 | 2 | 3 | 4 | 5;
let c: myType;
let d: myType;
c = 1;
// 这里就报错
d = 6;
本文标题:类型别名
本文链接:https://www.haomeiwen.com/subject/urwlsltx.html
网友评论