While enrolled in a JS course, I encountered the following code that was not functioning properly when added. Instead of returning the expected result, it returned 'undefined.' After investigating further, I identified that the issue lies within the "set fullName" function.
The error message displayed in VS code reads: "Property 'fullName' implicitly has type 'any', because its set accessor lacks a parameter type annotation."
Upon inspecting the console output, it became evident that the problem persists and continues to return 'undefined.'
I attempted to research the issue online and came across suggestions related to TypeScript versions. However, I am currently utilizing the latest version provided by VSCODE, which is TypeScript 3.9.0.
class Person {
constructor(firstname, lastName, age, likes = []) {
this.firstName = firstname
this.lastName = lastName
this.age = age
this.likes = likes
}
getBio() {
let bio = `${this.firstName} is ${this.age}.`
this.likes.forEach( (like) => {
bio = bio + ` ${this.firstName} likes ${like}.`
})
return bio
}
set fullName(fullName) {
const names = fullName.split(' ')
this.firstName = names[0]
this.lastName = names[1]
}
}