Complete the code to define a nested object type with a property 'address'.
type User = {
name: string;
address: [1];
};The property address is an object with nested properties street and city, so it needs an object type.
Complete the code to access the nested property 'city' from the user object.
const user: User = {
name: 'Alice',
address: { street: 'Main St', city: 'Wonderland' }
};
const cityName = user.address.[1];To get the city name, access the city property inside the address object.
Fix the error in the nested object type by completing the type for 'company'.
type Employee = {
id: number;
company: [1];
};The company property is an object with name and location properties, so it needs an object type.
Fill both blanks to define a nested object type with an array of objects.
type Book = {
title: string;
author: [1];
};
type Library = {
name: string;
books: [2][];
};The books property is an array of Book objects, and the author property inside Book is a string.
Fill all three blanks to define a nested object type with optional and nested properties.
type Profile = {
username: string;
contact: {
email: [1];
phone?: [2];
};
preferences: [3];
};The email is a string, phone is an optional number, and preferences is an object with theme and notifications properties.