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, "type" is shown in blue in Visual Studio 2013 with TypeScript 1.4:
interface IExampleInterface {
type: string;
}
Let's say that you then try to implement the interface in a class, like this:
class ExampleClass implements IExampleInterface {
public type: string;
constructor() {
this.type = "Example";
}
}
In the first line of the class, as you type (sorry) the word "type" in order to implement the property required by the interface, IntelliSense appears with "type" having the same icon as other keywords like "typeof" or "new".
I've had a look around, and could find this GitHub issue which lists "type" as a "strict mode reserved word" in TypeScript, but I have not found any further information about what its purpose actually is.
I suspect I'm having a brain fart and this is something obvious I should already know, but what is the "type" reserved word in TypeScript for?
It's used for "type aliases". For example:
type StringOrNumber = string | number;
type DictionaryOfStringAndPerson = Dictionary<string, Person>;
For reference, there is a section for type aliases in the TypeScript Handbook.