- 最終更新
- 2026/08/17
3秒でわかる
TypeScript で型に名前を付ける 2 つの構文。後から拡張したい型は interface、ユニオン型など型そのものの別名には type を使います。
30秒図解
もう少し詳しく
どういうものか
interface と type は
なぜ必要か
同じ形のtype は
具体例
interface User {
id: number;
name: string;
}
interface User {
email: string;
}
// 宣言マージにより User は id / name / email を持つ
type Status = "idle" | "loading" | "done";
type Result = { status: Status; user: User } | { status: "error"; message: string };
function render(r: Result) {
if (r.status === "error") return r.message;
return r.user.name;
}つまずきやすいところ
type はinterface は静かにマージされるので、interface でinterface はinterface は extends、type は & にinterface の似た用語との違い
| 観点 | interface | type |
|---|---|---|
| オブジェクトの形 | 書ける | 書ける |
| ユニオン型 | 書けない | 書ける |
| 同名の再宣言 | マージされる | エラー |
| 拡張 | extends | & で合成 |
覚え方
外から

