- 01Getting Started
- 02Your First Output (console.log)
- 03Variables and Type Annotations (number/string/boolean)
- 04Array Types
- 05Function Types (Parameters and Return Values)
- 06Optional Parameters and Default Parameters
- 07Interfaces (interface)
- 08Optional Properties (?)
- 09Type Aliases (type)
- 10Union Types
- 11Literal Types
- 12enum (Enumerated Types)
- 13Classes and Types
- 14Inheritance (extends) and Implementing an Interface (implements)
- 15Generics (<T>)
- 16Tuple Types
- 17The any and unknown Types
- 18Type Assertions (as)
- 19The readonly Modifier
- 20[Applied] Build a Mini Inventory Management System
Type Aliases (type)
This lesson covers type (a type alias), which lets you give a type a different name. It's for anyone searching "TypeScript type alias."
Writing type Name = type; attaches a short name to a complex type. This cuts down on repeating the same type over and over, and makes your code's intent easier to convey.
The example defines a type alias, type Point = { x: number; y: number };, and uses it for objects representing two coordinates.
A common early mistake is being unsure whether to use interface or type. For simply defining an object's shape, there's not much difference between the two, but for expressing "one of several possible types" โ like a union type, covered in the next lesson โ only type will work.
In real projects, teams and projects often settle on their own rule for when to use interface versus type.
๐งช This site can't compile or run TypeScript directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ nothing is sent anywhere).
