Q36. What is structural typing?

TypeScript is primarily structurally typed: compatibility depends on the members a value has, not only on a declared nominal name. This supports flexible object contracts and interfaces. Some features, such as private class members and unique symbols, can introduce nominal-like constraints.

An object with the required fields can often be assigned to an interface even if it was not declared with implements.

Note

Interview approach: define the concept, explain why it matters, then mention one trade-off or limitation.

TypeScript concept
// Illustrative TypeScript contract
type Identifier = string;
const id: Identifier = "item-1";
💡 The example demonstrates the compile-time contract discussed in this question.
Key Takeaways
  • Explain the concept in your own words.
  • Know the practical trade-off and its limits.
  • Use a small example to demonstrate the idea.
Knowledge Check

What primarily determines compatibility in structural typing?