Recall & Review
beginner
What does assignment compatibility mean in TypeScript?
It means you can assign a value of one type to a variable of another type if TypeScript considers the types compatible based on their structure.
Click to reveal answer
intermediate
How does TypeScript check assignment compatibility between two object types?
TypeScript checks if the source object has at least the properties and types required by the target object (structural typing). Extra properties in the source are allowed.
Click to reveal answer
beginner
What happens if you try to assign a value with missing required properties in TypeScript?
TypeScript will give an error because the source type does not have all the required properties of the target type, so they are not assignment compatible.
Click to reveal answer
intermediate
Can TypeScript assign a function type to another function type with fewer parameters?
Yes, TypeScript allows assigning a function with fewer parameters to one expecting more, as long as the parameters it does have are compatible (called function parameter bivariance).
Click to reveal answer
advanced
Does TypeScript consider private or protected members when checking assignment compatibility?
Yes, private and protected members must come from the same declaration for assignment compatibility; otherwise, the types are incompatible.
Click to reveal answer
In TypeScript, when is an object type assignment allowed?
✗ Incorrect
TypeScript uses structural typing, so the source must have at least the properties the target expects.
What happens if you assign a function with more parameters to a function type expecting fewer parameters?
✗ Incorrect
Assigning a function with more parameters to one expecting fewer is not allowed in TypeScript.
Are private members considered when checking assignment compatibility?
✗ Incorrect
Private and protected members must originate from the same declaration for compatibility.
Which typing system does TypeScript use to check assignment compatibility?
✗ Incorrect
TypeScript uses structural typing, meaning compatibility depends on the shape of types.
Can you assign a value of type 'number' to a variable of type 'string' in TypeScript?
✗ Incorrect
Number and string are incompatible types; direct assignment causes an error.
Explain how TypeScript checks assignment compatibility between two object types.
Think about the shape of the objects and member visibility.
You got /4 concepts.
Describe how function types are checked for assignment compatibility in TypeScript.
Consider how many parameters the functions have and their types.
You got /4 concepts.