Complete the code to declare an interface named Person.
interface [1] {
name: string;
age: number;
}The interface is named Person to describe a person's structure.
Complete the code to create a variable with the Person type.
const user: [1] = { name: 'Alice', age: 30 };
The variable user must have the type Person to match the interface.
Fix the error in the function parameter type to accept any object with name and age.
function greet(person: [1]) {
console.log(`Hello, ${person.name}!`);
}Using a structural type { name: string; age: number } allows any object with these properties.
Fill both blanks to create two types and check if they are compatible structurally.
type [1] = { id: number }; type [2] = { id: number; name: string }; const a: [1] = { id: 1 }; const b: [2] = { id: 2, name: 'Bob' }; const c: [1] = b; // Allowed because of structural typing
Type ID has only id. Type User has id and name. Assigning b to c works because User has all properties of ID.
Fill all three blanks to demonstrate nominal typing using classes and type compatibility.
class [1] { constructor(public id: number) {} private __brand[1]: void; } class [2] { constructor(public id: number, public name: string) {} private __brand[2]: void; } const x: [1] = new [2](1, 'Carol'); // Error in nominal typing
Classes ID and User are nominal types. Even if User has all properties of ID, they are not compatible by name. Assigning an instance of User to ID causes an error.