Skip to content

Commit 84d7620

Browse files
committed
Clarify interface vs type usage in docs
1 parent e60e420 commit 84d7620

1 file changed

Lines changed: 4 additions & 12 deletions

File tree

  • apps/web/src/app/(docs)/docs/conventions

apps/web/src/app/(docs)/docs/conventions/page.mdx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,13 @@ interface Example {
8383

8484
## Interface over type
8585

86-
Prefer `interface` over `type` for object shapes. TypeScript shows the interface name rather than expanding the whole structure, making types more readable.
86+
Prefer `interface` over `type` because interfaces always appear by name in error messages and tooltips.
8787

8888
Use `type` only when necessary:
8989

9090
- Union types: `type Status = "pending" | "done"`
9191
- Mapped types, tuples, or type utilities
9292

93-
```ts
94-
// Prefer interface for object shapes.
95-
interface User {
96-
readonly id: string;
97-
readonly name: string;
98-
}
99-
100-
// Use type for unions and utilities.
101-
type Status = "pending" | "done";
102-
type UserKeys = keyof User;
103-
```
93+
> Use `interface` until you need to use features from `type`.
94+
>
95+
> [TypeScript Handbook](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#differences-between-type-aliases-and-interfaces)

0 commit comments

Comments
 (0)