Complete the code to declare an object with a required property 'name'.
interface Person { name: string; }
const person: Person = { name: [1] };The property 'name' must be a string, so we use a string literal like "Alice".
Complete the code to assign an object with an extra property 'age' to a variable of type Person.
interface Person { name: string; }
const person: Person = { name: "Bob", [1]: 30 };The extra property 'age' is not declared in Person, so TypeScript will check for excess properties.
Fix the error in the code by completing the type assertion to allow extra properties.
interface Person { name: string; }
const p: Person = { name: "Carol", age: 25 } as [1];Using 'any' in a type assertion disables excess property checks, allowing extra properties.
Fill both blanks to create a function that accepts an object with at least a 'name' property and any extra properties.
function greet(person: [1] & [2]) { console.log(`Hello, ${person.name}`); }
The intersection of a specific type and a Record allows extra properties while requiring 'name'.
Fill all three blanks to create a variable with structural compatibility allowing extra properties without errors.
interface Person { name: string; }
const p: Person = { name: "Dave", [1]: 40, [2]: "blue" } as [3];Using 'any' as a type assertion allows assigning an object with extra properties to Person without errors.