What is the “type” reserved word in TypeScript?

前端 未结 2 1643
执念已碎
执念已碎 2020-12-02 13:01

I just noticed when trying to create an interface in TypeScript that \"type\" is either a keyword or a reserved word. When creating the following interface, for example, \"t

2条回答
  •  悲&欢浪女
    2020-12-02 13:09

    It's used for "type aliases". For example:

    type StringOrNumber = string | number;
    type DictionaryOfStringAndPerson = Dictionary;
    

    Reference: (edit: removed outdated link) TypeScript Specification v1.5 (section 3.9, "Type Aliases", pages 46 & 47)

    Update: (edit: removed outdated link) Now on section 3.10 of the 1.8 spec. Thanks @RandallFlagg for the updated spec and link

    Update: TypeScript Handbook, search "Type Aliases" can get you to the corresponding section.

提交回复
热议问题