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.

GroupType Composition
KindSyntax
Strict modeNot 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 = TThe 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.
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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏