TypeAliasDeclaration: BindingIdentifier TypeParametersopt Type
A type alias serves as an alias for the type specified in the type alias declaration. Unlike an interface declaration, which always introduces a named object type, a type alias declaration can introduce a name for any kind of type, including primitive, union, and intersection types.
A type alias may optionally have type parameters (section ) that serve as placeholders for actual types to be provided when the type alias is referenced in type references. A type alias with type parameters is called a generic type alias. The type parameters of a generic type alias declaration are in scope and may be referenced in the aliased Type.
The BindingIdentifier of a type alias declaration may not be one of the predefined type names (section 3.8.1).
It is an error for the type specified in a type alias to depend on that type alias. Types have the following dependencies:
- A type alias directly depends on the type it aliases.
- A type reference directly depends on the referenced type and each of the type arguments, if any.
- An array type directly depends on its element type.
- A tuple type directly depends on each of its element types.
Given this definition, the complete set of types upon which a type depends is the transitive closure of the directly depends on relationship. Note that object type literals, function type literals, and constructor type literals do not depend on types referenced within them and are therefore permitted to circularly reference themselves through type aliases.
Interface types have many similarities to type aliases for object type literals, but since interface types offer more capabilities they are generally preferred to type aliases. For example, the interface type
could be written as the type alias
However, doing so means the following capabilities are lost:
- An interface can be named in an extends or implements clause, but a type alias for an object type literal cannot.
- An interface can have multiple merged declarations, but a type alias for an object type literal cannot.