Book with a title propertyAuthorInfo with an author propertyPublicationInfo with a year propertyBook class with both interfacesBook with all properties and print its detailsBook with a title propertyAuthorInfo with an author propertyPublicationInfo with a year propertyBook class with both interfacesBook with all properties and print its detailsBook classBook with a constructor that takes a title string and stores it in a public property called title.Use constructor(public title: string) {} to create the class with a public property.
AuthorInfo and PublicationInfoAuthorInfo with a string property author, and PublicationInfo with a number property year.Use interface AuthorInfo { author: string; } and similarly for PublicationInfo.
Book class with interfacesBook class with the interfaces AuthorInfo and PublicationInfo by declaring that Book implements both interfaces. Add public properties author and year to the class and set them in the constructor.Use implements AuthorInfo, PublicationInfo after the class name and add the properties to the constructor.
myBook that is a new Book with title 'The TypeScript Guide', author 'Jane Doe', and year 2024. Then print the string `${myBook.title} by ${myBook.author}, published in ${myBook.year}`.Create the instance with new Book(...) and use console.log with a template string to print.
What happens when you declare an interface with the same name as a class in TypeScript?
For example:class Car { drive() {} }
interface Car { color: string; }
Which of the following is the correct syntax to merge an interface with a class named Person in TypeScript?
Given the following code, what is the output?
class Animal {
speak() { return "Roar"; }
}
interface Animal {
age: number;
}
const a: Animal = { age: 5, speak() { return "Roar"; } };
console.log(a.age, a.speak());Identify the error in this code that merges a class and interface named Book:
class Book {
title: string;
constructor(title: string) {
this.title = title;
}
}
interface Book {
author: string;
}
const b = new Book("1984");
console.log(b.author);You want to extend a class Employee by merging an interface with the same name to add a new method getSalary(). How should you correctly implement this so that getSalary() is usable on Employee instances?
class Employee {
name: string;
constructor(name: string) {
this.name = name;
}
}
interface Employee {
getSalary(): number;
}
// What is the correct way to implement getSalary?Pass the test and this pattern moves unknown