You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/web/src/app/(docs)/docs/conventions/page.mdx
+4-12Lines changed: 4 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -83,21 +83,13 @@ interface Example {
83
83
84
84
## Interface over type
85
85
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.
87
87
88
88
Use `type` only when necessary:
89
89
90
90
- Union types: `type Status = "pending" | "done"`
91
91
- Mapped types, tuples, or type utilities
92
92
93
-
```ts
94
-
// Prefer interface for object shapes.
95
-
interfaceUser {
96
-
readonly id:string;
97
-
readonly name:string;
98
-
}
99
-
100
-
// Use type for unions and utilities.
101
-
typeStatus="pending"|"done";
102
-
typeUserKeys=keyofUser;
103
-
```
93
+
> Use `interface` until you need to use features from `type`.
0 commit comments