Explain the differences and use-cases for 'interface' vs 'type' aliases in TypeScript.

Instruction: Provide examples to highlight when and why you would use one over the other.

Context: This question assesses the candidate's deep understanding of TypeScript's type system, particularly the nuances and appropriate use-cases of interfaces and type aliases.

Updated

Official answer available

Read the opening below, then unlock the full answer and practical guidance.

Both interface and type can describe structural object contracts. An interface can be reopened through compatible declaration merging. A type alias can name an object, primitive, union, tuple or computed type, but cannot be reopened with a second declaration of the same alias.

```typescript interface UserProfile { username: string } interface UserProfile { preferences: string[] } const profile: UserProfile = { username: "Ada", preferences: [] };...

Related Questions