type Type Aliases
Last updated: 2026-10-22
type Type Aliases
type names any type — objects, unions, tuples, functions, literals — making it the most general way to name types, alongside interface.
| Group | Type Composition |
|---|---|
| Kind | Syntax |
| Strict mode | Not required |
ℹ️ Info The editor transpiles TypeScript to JavaScript and runs it (no type checking); see each example's Output for type-check results.
📝 Syntax
type ID = string | number;
type Point = { x: number; y: number };
const origin: Point = { x: 0, y: 0 };
⚙️ Parameters
| type X = T | The right side can be any type expression: unions, intersections, tuples, conditionals |
|---|
Returns:None — type is type-level only and disappears after compilation.
▶ Example
Edit the code below and click Try it to see the transpiled result:
Output:
#42 #A1 0 0
(Runtime output after transpilation; adding z: 1 to origin triggers the excess property check)
💡 Notes
ℹ️ Info type expresses unions, tuples, mapped and conditional types that interface cannot; interface's declaration merging is unavailable to type.
💡 Tip Naming complex shapes shortens error messages — errors show the alias, not a wall of structure.
⚠️ Note Same-named type declarations collide (duplicate definition error) — unlike interface merging; layer extensions via intersection types instead.
🏷️ Related Type Composition
💡 Related cases
More cases coming soon.
📚 Related tutorials
❓ FAQ
Q type or interface — which one?
A Pick one per team. Rule of thumb: interface for plain object shapes that might be merged/augmented; type whenever unions or utility composition is involved.
Q Can a type reference itself recursively?
A Yes — type JSON = string | number | boolean | null | JSON[] | { [k: string]: JSON }. interface supports recursion too.
Q Do type names affect runtime?
A No. type is a compile-time alias only, fully erased after transpilation — only values exist at runtime.