Repaso
Español
Frontend & WebAdvancedFE-21

TypeScript's type system is…

Options

  1. Nominal: types match only by their declared name
  2. Structural: types are compatible if shapes match (Correct option)
  3. Dynamic: types are checked at runtime instead
  4. Identical to the type system that Java uses

Answer

Structural: types are compatible if their shapes match

Why

TypeScript compares the SHAPE of types, not their names. If an interface requires { id: number; name: string }, any object with those properties fits, even if it was never declared as that interface.

Also, types disappear when TypeScript compiles to JavaScript, so data from outside still needs runtime validation.

Remember

TypeScript checks shape, not name, and only at compile time.

Key terms

Practice this question in Repaso