Book class with a constructor that takes title and author as stringsBookParams using ConstructorParameters for the Book classcreateBook that takes BookParams as its parameter and returns a new Book instanceBook class with a constructor that takes title and author as stringsBookParams using ConstructorParameters for the Book classcreateBook that takes BookParams as its parameter and returns a new Book instanceBook with a constructor that takes two parameters: title and author, both of type string. Store these parameters as public properties.Use constructor(public title: string, public author: string) {} to create and store the properties.
BookParams that uses ConstructorParameters with the typeof Book to get the constructor parameter types.Use type BookParams = ConstructorParameters to extract the constructor parameters.
createBook that takes one parameter named params of type BookParams. The function should return a new Book instance using the spread operator to pass params to the Book constructor.Use return new Book(...params); inside the function to create the book.
createBook function with the parameters "The Hobbit" and "J.R.R. Tolkien". Store the result in a variable called myBook. Then print the book's title and author using console.log.Use console.log(`Title: ${myBook.title}, Author: ${myBook.author}`); to print the details.
What does the ConstructorParameters type utility do in TypeScript?
ConstructorParameters utility extracts the types of the parameters used in a class constructor and returns them as a tuple type.ConstructorParameters does not perform.Which of the following is the correct syntax to get the constructor parameter types of a class MyClass using ConstructorParameters?
class MyClass { constructor(name: string, age: number) {} }typeof MyClass (the class constructor type), not the instance type.typeof MyClass.What is the output type of the following code?
class Person {
constructor(public name: string, public age: number) {}
}
type Params = ConstructorParameters<typeof Person>;name of type string and age of type number.ConstructorParameters<typeof Person> returns a tuple of the parameter types: [string, number].Identify the error in this code snippet:
class Car {
constructor(make: string, year: number) {}
}
type Params = ConstructorParameters<Car>;typeof Car, not the instance type Car.Car directly causes a type error because it is the instance type, not the constructor type.Given the following classes, how can you create a type alias EmployeeParams that matches the constructor parameters of Employee by reusing the constructor parameters of Person?
class Person {
constructor(public name: string, public age: number) {}
}
class Employee extends Person {
constructor(name: string, age: number, public salary: number) {
super(name, age);
}
}Person constructor takes name and age. Employee adds salary as a third parameter.ConstructorParameters<typeof Person> gives [string, number]. Adding number for salary creates [string, number, number].Pass the test and this pattern moves unknown