You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
type Name = string;
// NameResolver表示这是一个函数类型,并且函数的返回值类型是string
type NameResolver = () => string;
type NameOrResolver = Name | NameResolver;
function getName(n: NameOrResolver): Name {
if (typeof n === 'string') {
return n;
}
else {
return n();
}
}
The text was updated successfully, but these errors were encountered:
类型别名通常用来给一个类型取新名字。本质上不会创建一个新的类型,而是对原有类型的引用。
语法
type 新名字 = 类型
简单的例子
The text was updated successfully, but these errors were encountered: