0
0
Typescriptprogramming~5 mins

Excess property checking behavior in Typescript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is excess property checking in TypeScript?
Excess property checking is a TypeScript feature that warns you when you provide extra properties in an object literal that are not expected by the target type.
Click to reveal answer
intermediate
Why does TypeScript perform excess property checking only on object literals?
TypeScript checks object literals for extra properties to catch typos or mistakes early. It does not check variables or objects assigned from elsewhere to allow flexibility.
Click to reveal answer
intermediate
How can you avoid excess property checking errors when passing objects with extra properties?
You can assign the object to a variable first, or use type assertions to tell TypeScript to trust your object shape and skip excess property checks.
Click to reveal answer
beginner
What happens if you pass an object literal with an extra property to a function expecting a specific type?
TypeScript will give an error about the extra property because it does excess property checking on object literals to prevent mistakes.
Click to reveal answer
advanced
Can excess property checking be bypassed by using index signatures in TypeScript interfaces?
Yes, if an interface has an index signature like [key: string]: any, excess property checking is relaxed because extra properties are allowed.
Click to reveal answer
When does TypeScript perform excess property checking?
AOn all objects, including variables and function returns
BOnly on arrays
COnly on object literals assigned directly to variables or parameters
DOnly on primitive types
What error will TypeScript give if you pass an object literal with an unexpected property to a function expecting a specific type?
AExcess property error
BSyntax error
CRuntime error
DNo error
How can you avoid excess property checking errors when you want to pass extra properties?
AUse a number instead of an object
BUse a different programming language
CRemove all properties
DAssign the object to a variable before passing it
What effect does an index signature have on excess property checking?
AIt disables excess property checking for extra properties
BIt causes more errors
CIt only allows numeric keys
DIt has no effect
Which of these is a common reason for excess property checking errors?
APassing a number instead of an object
BA typo in a property name in an object literal
CUsing a variable instead of an object literal
DUsing a function instead of an object
Explain what excess property checking is and why TypeScript uses it.
Think about how TypeScript helps catch typos in object properties.
You got /3 concepts.
    Describe two ways to avoid excess property checking errors when passing objects with extra properties.
    Consider how you can tell TypeScript to trust your object shape.
    You got /3 concepts.