From the course: TypeScript Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Defining types using type aliases

Defining types using type aliases - TypeScript Tutorial

From the course: TypeScript Essential Training

Defining types using type aliases

- So far in this chapter, I showed you how to use the primitive and built in types that JavaScript offers, as well as how to define your own custom types using interfaces. One other way of referring to types and defining your own custom types is called a type alias. As its name implies, a type alias is simply providing an alias or alternate name for an already existing type. You define a type alias using the type keyword followed by the name of the alias. Let's call this one ContactName. Then follow that with an equal sign and the type you wish to alias, in this case string. Now that I've defined the type alias, I can use it in any place that I would use the original type. For example, I can refactor the contact interface example from the previous video, changing the type of the name field from string to ContactName. Note however, the type aliases are truly just that, an alias for another type. They are not a new…

Contents