Complete the code to declare that the class implements the interface.
interface Animal {
makeSound(): void;
}
class Dog implements Animal {
makeSound() {
console.log('Woof!');
}
}The keyword implements is used in TypeScript to declare that a class follows an interface.
Complete the code to add a property from the interface to the class.
interface Vehicle {
wheels: number;
drive(): void;
}
class Car implements Vehicle {
[1]: number = 4;
drive() {
console.log('Driving');
}
}The class must have the property named exactly as in the interface, which is wheels.
Fix the error by completing the method signature to match the interface.
interface Speaker {
speak(words: string): void;
}
class Person implements Speaker {
speak([1]) {
console.log(words);
}
}The method parameter must match the interface exactly: name and type. Here it is words: string.
Fill both blanks to complete the class implementing the interface with a constructor.
interface User {
name: string;
age: number;
}
class Member implements User {
[1]: string;
[2]: number;
constructor(name: string, age: number) {
this.name = name;
this.age = age;
}
}The class must have properties named exactly as in the interface: name and age.
Fill all three blanks to implement the interface with a method and property.
interface Logger {
level: string;
log(message: string): void;
}
class ConsoleLogger implements Logger {
[1]: string = 'info';
[2](message: string): void {
console.log(`[$[3]] ${message}`);
}
}this to access the property inside the method.The class must have the property level, the method log, and inside the method use this.level to access the property.