Complete the code to get the instance type of the class.
class Person { name: string; constructor(name: string) { this.name = name; } } type PersonInstance = [1]<typeof Person>;
The InstanceType type extracts the instance type from a class constructor type.
Complete the code to create an instance of the class using the instance type.
class Car { model: string; constructor(model: string) { this.model = model; } } type CarInstance = InstanceType<typeof Car>; const myCar: [1] = new Car('Tesla');
Car instead of the instance type aliastypeof Car which is the constructor typeThe variable myCar should be typed as the instance type of Car, which is CarInstance.
Fix the error in the code by completing the type alias correctly.
class Animal { species: string; constructor(species: string) { this.species = species; } } type AnimalInstance = [1];
Animal directly instead of typeof AnimalThe InstanceType utility requires a constructor type, so we must pass typeof Animal inside the angle brackets.
Fill both blanks to create a type alias for the instance type and declare a variable of that type.
class Book { title: string; constructor(title: string) { this.title = title; } } type [1] = [2]<typeof Book>; const myBook: BookInstance = new Book('1984');
ReturnType instead of InstanceTypeThe type alias should be named BookInstance and use InstanceType with typeof Book.
Fill all three blanks to create an instance type alias, declare a variable, and access a property.
class User { username: string; constructor(username: string) { this.username = username; } } type [1] = [2]<typeof User>; const user: UserInstance = new User('alice'); const name: string = user.[3];
userName with uppercase NInstanceType with typeof UserThe alias is UserInstance, using InstanceType with typeof User. The property to access is username.