typescript interface vs type
- User
typescript interface vs type
Assistant
In TypeScript, there are two main ways to define object types:
- Interfaces:
interface User { name: string; age: number; }- Type aliases:
type User = { name: string; age: number; }The main differences between interfaces and type aliases are:
-
Interfaces can be extended and implemented by classes, type aliases can't.
-
Interfaces create a new name that is used everywhere. Type aliases simply create a new name for an existing type.
-
Interfaces can be merged, type aliases can't.
Some examples:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.