Unknown model· unknown
NVIDIA HelpSteer3 Preference
In typescript, explain simply when to use type and interface.
- User
In typescript, explain simply when to use type and interface.
- Assistant
In TypeScript, both
typeandinterfaceare used to define the structure or shape of an object or a function. However, they have some differences and are used in different scenarios:type: Usetypewhen you want to create a type alias for a complex object or a primitive type. It's also useful when you want to create a union type or an intersection type. For example:
typescripttype User = { name: string; age: number; }; type ID = string | number;interface: Useinterfacewhen you want to define a contract or a blueprint for an object. It's also useful when you want to extend or implement an existing interface. For example:
typescriptinterface User { name: string; age: number; } interface Admin extends User { role: string; }In summary, use
typewhen you want to create a type alias for a complex object or a primitive type, and useinterfacewhen you want to define a contract or a blueprint for an object.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.