Recall & Review
beginner
What is an inline object type annotation in TypeScript?
It is a way to specify the shape of an object directly where it is used, without creating a separate interface or type alias.
Click to reveal answer
beginner
How do you write an inline object type annotation for a function parameter that expects an object with a string 'name' and a number 'age'?
You write it like this: <pre>function greet(person: { name: string; age: number }) { ... }</pre>Click to reveal answer
intermediate
Why use inline object type annotations instead of interfaces?
Inline annotations are quick and simple for small or one-time use objects, avoiding extra code for interfaces when not needed.
Click to reveal answer
intermediate
Can inline object type annotations include optional properties? How?
Yes, by adding a question mark after the property name. Example:
{ name: string; age?: number } means 'age' is optional.Click to reveal answer
beginner
What happens if you pass an object missing a required property in an inline type annotation?
TypeScript will show an error because the object does not match the expected shape defined inline.
Click to reveal answer
How do you annotate a function parameter inline to accept an object with a 'title' string and 'pages' number?
✗ Incorrect
Option A correctly uses inline object type annotation with properties 'title' and 'pages'.
Which syntax shows an optional property 'color' in an inline object type?
✗ Incorrect
Option A uses the correct TypeScript syntax for optional properties with a question mark after the property name.
What is the benefit of inline object type annotations?
✗ Incorrect
Inline annotations are useful for quick, simple type definitions without extra code.
If a function expects parameter: { id: number; name: string }, what happens if you pass { id: 1 }?
✗ Incorrect
TypeScript checks types at compile time and will error if required properties are missing.
Which is a correct inline object type annotation for a variable holding a point with x and y as numbers?
✗ Incorrect
Option B correctly uses inline object type annotation with properties x and y.
Explain how to use inline object type annotation for a function parameter in TypeScript.
Think about writing the type directly inside the function parameter parentheses.
You got /3 concepts.
Describe how optional properties are declared in inline object type annotations and why they are useful.
Optional means the property may or may not be present.
You got /3 concepts.