Recall & Review
beginner
What is a fresh object literal in TypeScript?
A fresh object literal is a newly created object directly written in the code, which TypeScript treats with exact property checks during type assignment.
Click to reveal answer
intermediate
How does TypeScript treat object literals differently from variables when assigning to a typed variable?
TypeScript performs strict property checks on fresh object literals, disallowing extra properties. Variables assigned to objects are treated as non-fresh, so extra properties are allowed if the target type is compatible.
Click to reveal answer
intermediate
Why does TypeScript sometimes give an error for extra properties in object literals but not for variables?
Because fresh object literals are checked strictly for extra properties to catch mistakes early, while variables are assumed to be intentionally typed and allow extra properties if compatible.
Click to reveal answer
beginner
What happens if you assign a fresh object literal with extra properties to a variable typed with fewer properties?
TypeScript will give an error about excess properties because fresh object literals are checked strictly for extra properties not in the target type.
Click to reveal answer
intermediate
How can you avoid excess property errors when assigning fresh object literals in TypeScript?
You can assign the object literal to a variable first, then assign that variable to the typed variable, or use type assertions to tell TypeScript to trust the type.
Click to reveal answer
What does TypeScript call an object created directly in the code with properties listed inside curly braces?
✗ Incorrect
An object created directly with curly braces and properties is called a fresh object literal in TypeScript.
Why does TypeScript give an error when assigning an object literal with extra properties to a typed variable?
✗ Incorrect
TypeScript performs excess property checks on fresh object literals to catch mistakes early.
How can you assign an object with extra properties to a typed variable without error?
✗ Incorrect
Assigning the object literal to a variable first makes it non-fresh, so TypeScript allows extra properties.
What is the main difference between fresh object literals and variables in TypeScript type checking?
✗ Incorrect
Fresh object literals get excess property checks, while variables do not.
Which of these is a valid way to silence excess property errors in TypeScript?
✗ Incorrect
Using a type assertion tells TypeScript to trust the type and skip excess property checks.
Explain the difference between fresh object literals and variables in TypeScript when assigning to typed variables.
Think about how TypeScript checks extra properties differently for direct objects vs variables.
You got /4 concepts.
Describe two ways to avoid excess property errors when assigning objects in TypeScript.
Consider how TypeScript treats fresh vs non-fresh objects and how assertions affect checking.
You got /3 concepts.