Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
2 contributors

Users who have contributed to this file

@xcatliu @zenghongtu
32 lines (22 sloc) 789 Bytes

类型别名

类型别名用来给一个类型起个新名字。

简单的例子

type Name = string;
type NameResolver = () => string;
type NameOrResolver = Name | NameResolver;
function getName(n: NameOrResolver): Name {
    if (typeof n === 'string') {
        return n;
    } else {
        return n();
    }
}

上例中,我们使用 type 创建类型别名。

类型别名常用于联合类型。

参考


You can’t perform that action at this time.