Type Alias
What
A type alias allows you to create a custom name for an existing type or a complex type structure.
How
Use the type keyword followed by your custom name and the type definition:
type ID = string | number;
type Callback = (data: string) => void;
function process(id: ID, cb: Callback) {
// ...
}
Why
Type aliases improve code maintainability and readability. They allow you to define a complex shape in one place and reuse it throughout your application, making your code cleaner and significantly reducing the risk of errors when updating shared types.
Summary
Use type aliases to give semantic meaning to complex types and to centralize your type definitions for easier management.