Type aliases (type)
A type alias gives a name to a type so you write it once and reuse it.
A alias is written type Name = .... On the right goes any type: an object, a union, an array, a function.
How to read it: "Todo means this type". It does not create a new value or a class. It is only a name for something you could already write.
It is written this way for a practical reason: without an alias you would repeat the object's shape in every parameter and every return. If the shape changes, you change one place.
The type checker (tsc) uses the alias to check your code. When Node runs the file, the types are gone: Node strips them.
In the course you see export type Todo = { id: number; title: string; done: boolean };. With export, other files can import that type.
type Id = number;
Reach for it when: the same type shape appears in more than one place, or when a name makes the code clearer.
Examples
Common mistake
type Todo = { id: number; title: string };
const t: Todo = { id: 1, title: 5 };
console.log(t);Why: The alias fixes the shape. `title` must be a string and you gave it a number.
How to write it: Give a value of the right type: title: "Learn".
Common mistake
type Todo = { id: number; title: string };
const t: Todo = { id: 1 };
console.log(t);Why: The property `title` is missing, and the alias requires it.
How to write it: Add title, or mark it optional with title?: string if it can truly be missing.
