Type Aliases: Introduction
A type alias is a shorthand name for a type specifier or definition. Once a type alias has been defined, it can be used in nearly any context in which the associated type is permitted. The only context type aliases aren't allowed is on the right-hand side of an
instanceof, due to technical limitations with generics.
Any given type can have multiple aliases, and a type alias can itself have aliases. Type aliases can be parameterized or generic.
In the following example:
Counteris defined to be an alias for
Pointis defined to be an alias for a tuple of two
Estimateis defined to be an alias for a
StringTransformeris defined to be an alias for a callable that returns a nullable
MyCallback<T>is defined to be an alias to a generic callable that returns
<?hh type Counter = int; newtype Point = (int, int); newtype Estimate = Pair<int, float>; newtype StringTransformer = (function(string): ?string); newtype MyCallback<T> = (function(T): void);