Mascara: Next Generation JavaScript compiler

Try it Download Buy About Documentation Blog Contact

'type' keyword

The type-keyword is used to define new types by combining existing types.

Examples of where it may be useful:

Defining a shorthand for a parameterized type

Example:
type StringArray = Array.<String>;
 
var x : StringArray = [];
x[1] = "hello";
x[2] = 17;  //--> type error
A shorthand type (like StringArray in the example) is like an interface - it can be used in type annotations and signatures, but cannot be instantiated like a class.

Defining a union type

type NumberOrBool = (Number|boolan); 
(See also union types)

Modifying Nullability

type FierceObject = !Object;

Defines a new type which is like an Object, but which are not allowed to be null. (See also nullability)

X Try!
Mascara JavaScript Generated JavaScript

Translating...
Show compiler settings