类型别名 type
有的时候参数的类型可能会有很多,如果都列举出来的话代码看着会很臃肿。可以把它拆分出来,用type进行类型别名的设置。
function ss(id: string | number) {
console.log(id);
}
ss(123);
type idType = string | number;
function ss(id:idType ) {
console.log(id);
}
ss(123);
有的时候参数的类型可能会有很多,如果都列举出来的话代码看着会很臃肿。可以把它拆分出来,用type进行类型别名的设置。
function ss(id: string | number) {
console.log(id);
}
ss(123);
type idType = string | number;
function ss(id:idType ) {
console.log(id);
}
ss(123);