Complete the code to access the type of the 'name' property from the Person interface.
interface Person {
name: string;
age: number;
}
type NameType = Person[1];In TypeScript, to get the type of a property using indexed access types, you use square brackets with the property name as a string literal, like Person['name'].
Complete the code to define a type that represents the type of the 'age' property in the Person interface.
interface Person {
name: string;
age: number;
}
type AgeType = Person[1];The correct syntax to get the type of the 'age' property is Person['age']. This uses indexed access types with the property name as a string literal.
Fix the error in the code to correctly get the type of the 'email' property from the User interface.
interface User {
email: string;
id: number;
}
type EmailType = User[1];The correct way to get the type of a property is using square brackets with the property name as a string literal: User['email'].
Fill both blanks to create a type that represents the type of the property given by the generic key K in the Data interface.
interface Data {
title: string;
count: number;
}
type ValueType<K extends keyof Data> = Data[1]K[2];To access a property type using a generic key, use square brackets around the key: Data[K].
Complete the code to create a type that extracts the type of the 'status' property from the Response interface and makes it optional.
interface Response {
status: string;
data: object;
}
type OptionalStatus = Partial<{ [1]: Response['status'] }>;The correct way is to create a partial type with the key 'status' and its type accessed by Response['status']. So the blanks are filled with status, [, and ].