TypeScript编译器源码中的类型大全

图片

最近在看 TypeScript 编译器源码时,在 src\compiler\types.ts 文件中看到了 TypeFlags 枚举,该枚举列出了 TypeScript 所有内置类型,可以算是内置类型大全了,感觉对熟悉TypeScript类型系统很有参考意义,感兴趣的朋友们可以了解一下。

export const enum TypeFlags {    Any             = 1 << 0,    Unknown         = 1 << 1,    String          = 1 << 2,    Number          = 1 << 3,    Boolean         = 1 << 4,    Enum            = 1 << 5,   // Numeric computed enum member value    BigInt          = 1 << 6,    StringLiteral   = 1 << 7,    NumberLiteral   = 1 << 8,    BooleanLiteral  = 1 << 9,    EnumLiteral     = 1 << 10,  // Always combined with StringLiteral, NumberLiteral, or Union    BigIntLiteral   = 1 << 11,    ESSymbol        = 1 << 12,  // Type of symbol primitive introduced in ES6    UniqueESSymbol  = 1 << 13,  // unique symbol    Void            = 1 << 14,    Undefined       = 1 << 15,    Null            = 1 << 16,    Never           = 1 << 17,  // Never type    TypeParameter   = 1 << 18,  // Type parameter    Object          = 1 << 19,  // Object type    Union           = 1 << 20,  // Union (T | U)    Intersection    = 1 << 21,  // Intersection (T & U)    Index           = 1 << 22,  // keyof T    IndexedAccess   = 1 << 23,  // T[K]    Conditional     = 1 << 24,  // T extends U ? X : Y    Substitution    = 1 << 25,  // Type parameter substitution    NonPrimitive    = 1 << 26,  // intrinsic object type    TemplateLiteral = 1 << 27,  // Template literal type    StringMapping   = 1 << 28,  // Uppercase/Lowercase type    /** @internal */    Reserved1       = 1 << 29,  // Used by union/intersection type construction
    /** @internal */    AnyOrUnknown = Any | Unknown,    /** @internal */    Nullable = Undefined | Null,    Literal = StringLiteral | NumberLiteral | BigIntLiteral | BooleanLiteral,    Unit = Enum | Literal | UniqueESSymbol | Nullable,    Freshable = Enum | Literal,    StringOrNumberLiteral = StringLiteral | NumberLiteral,    /** @internal */    StringOrNumberLiteralOrUnique = StringLiteral | NumberLiteral | UniqueESSymbol,    /** @internal */    DefinitelyFalsy = StringLiteral | NumberLiteral | BigIntLiteral | BooleanLiteral | Void | Undefined | Null,    PossiblyFalsy = DefinitelyFalsy | String | Number | BigInt | Boolean,    /** @internal */    Intrinsic = Any | Unknown | String | Number | BigInt | Boolean | BooleanLiteral | ESSymbol | Void | Undefined | Null | Never | NonPrimitive,    StringLike = String | StringLiteral | TemplateLiteral | StringMapping,    NumberLike = Number | NumberLiteral | Enum,    BigIntLike = BigInt | BigIntLiteral,    BooleanLike = Boolean | BooleanLiteral,    EnumLike = Enum | EnumLiteral,    ESSymbolLike = ESSymbol | UniqueESSymbol,    VoidLike = Void | Undefined,    /** @internal */    Primitive = StringLike | NumberLike | BigIntLike | BooleanLike | EnumLike | ESSymbolLike | VoidLike | Null,    /** @internal */    DefinitelyNonNullable = StringLike | NumberLike | BigIntLike | BooleanLike | EnumLike | ESSymbolLike | Object | NonPrimitive,    /** @internal */    DisjointDomains = NonPrimitive | StringLike | NumberLike | BigIntLike | BooleanLike | ESSymbolLike | VoidLike | Null,    UnionOrIntersection = Union | Intersection,    StructuredType = Object | Union | Intersection,    TypeVariable = TypeParameter | IndexedAccess,    InstantiableNonPrimitive = TypeVariable | Conditional | Substitution,    InstantiablePrimitive = Index | TemplateLiteral | StringMapping,    Instantiable = InstantiableNonPrimitive | InstantiablePrimitive,    StructuredOrInstantiable = StructuredType | Instantiable,    /** @internal */    ObjectFlagsType = Any | Nullable | Never | Object | Union | Intersection,    /** @internal */    Simplifiable = IndexedAccess | Conditional,    /** @internal */    Singleton = Any | Unknown | String | Number | Boolean | BigInt | ESSymbol | Void | Undefined | Null | Never | NonPrimitive,    // 'Narrowable' types are types where narrowing actually narrows.    // This *should* be every type other than null, undefined, void, and never    Narrowable = Any | Unknown | StructuredOrInstantiable | StringLike | NumberLike | BigIntLike | BooleanLike | ESSymbol | UniqueESSymbol | NonPrimitive,    // The following flags are aggregated during union and intersection type construction    /** @internal */    IncludesMask = Any | Unknown | Primitive | Never | Object | Union | Intersection | NonPrimitive | TemplateLiteral | StringMapping,    // The following flags are used for different purposes during union and intersection type construction    /** @internal */    IncludesMissingType = TypeParameter,    /** @internal */    IncludesNonWideningType = Index,    /** @internal */    IncludesWildcard = IndexedAccess,    /** @internal */    IncludesEmptyObject = Conditional,    /** @internal */    IncludesInstantiable = Substitution,    /** @internal */    IncludesConstrainedTypeVariable = Reserved1,    /** @internal */    NotPrimitiveUnion = Any | Unknown | Void | Never | Object | Intersection | IncludesInstantiable,}

 欢迎关注公众号:文本魔术,了解更多

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值