0
0
Typescriptprogramming~5 mins

How structural typing differs from nominal typing in Typescript - Quick Revision & Summary

Choose your learning style9 modes available
Recall & Review
beginner
What is structural typing?
Structural typing means that two types are compatible if their shapes (properties and methods) match, regardless of their names.
Click to reveal answer
beginner
What is nominal typing?
Nominal typing means that two types are compatible only if they have the same name or explicitly declared relationship, regardless of their structure.
Click to reveal answer
beginner
How does TypeScript use typing?
TypeScript uses structural typing, so it checks if types have matching properties and methods rather than relying on type names.
Click to reveal answer
intermediate
Example: Why are two objects with the same properties compatible in structural typing?
Because structural typing compares the shape (properties and methods), two objects with the same shape are considered the same type even if their names differ.
Click to reveal answer
intermediate
Why might nominal typing be preferred in some languages?
Nominal typing helps catch errors by requiring explicit type relationships, making sure only intended types are compatible, which can improve safety.
Click to reveal answer
In structural typing, two types are compatible if:
AThey have the same shape (properties and methods).
BThey have the same name.
CThey are declared in the same file.
DThey have different properties.
Which typing system requires explicit type names to match for compatibility?
AStructural typing
BDynamic typing
CDuck typing
DNominal typing
TypeScript primarily uses which typing system?
ANominal typing
BDynamic typing
CStructural typing
DDuck typing
If two objects have the same properties but different names, are they compatible in TypeScript?
ANo, because names must match.
BYes, because TypeScript uses structural typing.
COnly if explicitly declared.
DOnly if they are classes.
Which typing system can help prevent accidental type compatibility?
ANominal typing
BStructural typing
CDuck typing
DDynamic typing
Explain in your own words how structural typing differs from nominal typing.
Think about whether type names or properties matter more.
You got /3 concepts.
    Why might a language choose nominal typing over structural typing?
    Consider how strict the type system should be.
    You got /3 concepts.