midTypeScript
Explain 'Nominal vs Structural' typing and how TS handles them.
Updated May 4, 2026
Short answer
Structural typing (TS) compares the shapes of members; Nominal typing (Java/C#) compares the explicit names of types.
Deep explanation
TypeScript's structural type system allows for great flexibility. If an object has the required properties, it is considered a valid implementation of an interface, regardless of whether it explicitly 'implements' it. This is based on the principle that JavaScript is dynamic and duck-typed. However, for cases where you need exact type identity, developers use 'branding' to simulate nominal typing.
Real-world example
Passing a 'User' object from a database directly into a function expecting a 'Profile' interface because they share the same fields.
Common mistakes
- Assuming that two classes with the same structure are 'different' types in logic, which can lead to passing the wrong data if not careful.
Follow-up questions
- How do you achieve Nominal typing in TS?