Complete the code to declare a typed class property.
class Person { name: [1]; constructor(name: string) { this.name = name; } }
The name property should be typed as string because it holds text.
Complete the code to add a typed method that returns the person's name.
class Person { name: string; constructor(name: string) { this.name = name; } getName(): [1] { return this.name; } }
The method getName returns the name which is a string, so its return type must be string.
Fix the error in the class by typing the age property correctly.
class Person { name: string; age: [1]; constructor(name: string, age: number) { this.name = name; this.age = age; } }
The age property should be typed as number because it holds numeric data.
Fill both blanks to create a typed method that sets the person's age.
class Person { age: number; setAge([1]: [2]) { this.age = age; } }
The method parameter should be named age and typed as number to match the property.
Fill all three blanks to create a typed class with a constructor and a method that returns a greeting.
class Person { name: [1]; constructor(name: [2]) { this.name = name; } greet(): [3] { return `Hello, ${this.name}!`; } }
The name property and constructor parameter should be typed as string. The greet method returns a string greeting.