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:
✗ Incorrect
Structural typing checks if the shapes match, not the names.
Which typing system requires explicit type names to match for compatibility?
✗ Incorrect
Nominal typing requires type names or explicit declarations to match.
TypeScript primarily uses which typing system?
✗ Incorrect
TypeScript uses structural typing to check type compatibility.
If two objects have the same properties but different names, are they compatible in TypeScript?
✗ Incorrect
TypeScript compares object shapes, so names don't matter.
Which typing system can help prevent accidental type compatibility?
✗ Incorrect
Nominal typing requires explicit type matches, reducing accidental compatibility.
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.