The property 'fullName' is assumed to have type 'any' due to the missing parameter type annotation in its set accessor

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]
}

}

Answer №1

the issue is located within your tsconfig.

You will find a file named tsconfig.json in the root of your project that includes this line:

noImplicitAny: "true"

If you do not have a tsconfig.json, then VS Code likely uses a default configuration with this setting, and you can create a tsconfig to customize it.

This means that you are unable to write code where the type is implicitly any; you must explicitly declare its type or structure it in a way where its type can be inferred. You have the option to switch this setting to false (not recommended) or explicitly define your types.

set fullName(fullName: string) {

It's a good practice to consistently do this:

constructor(firstname: string, lastName: string, age: number, likes: string[] = []) {

On a side note, it seems like the course material may be outdated or not optimized for TypeScript if they permit coding with implicit any.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Link varying columns to a table with the power of AngularJS

I'm currently facing a challenge with displaying data on a table that I fetch from an external service. The issue lies in the fact that the data received from the service varies in terms of columns, sometimes there are 5 columns and other times there ...

AngularJS + Asynchronous Operations

I'm working with AngularJS and I have two API methods in my factory. I've been trying to call these two methods one after the other, but it's not functioning as expected. The desired sequence is to first execute test1 followed by test2. Be ...

Exploring the process of cycling through "Fetch" JSON data in React.js for a dynamic slider component after setting it to state

Still getting the hang of React, so please go easy on me! My main objective is to retrieve data from my personal JSON server and display it on a custom "Slider" component that I'm working on. Following a tutorial, I wanted to challenge myself by usi ...

Tips for concealing a button post-click

Just updated my code, please take a look! I have created a button using HTML, CSS, and JavaScript and I am trying to figure out how to hide it once it's clicked. Below is the HTML for the button that should play music when clicked: <audio id="my ...

"Implement a feature to recognize and handle various file extensions within an npm

I need help with my npm script where I am trying to include both ts and tsx file extensions. My current code snippet is as follows: "test": "mocha ..... app/test/**/*.spec.{ts,tsx}" Unfortunately, the above syntax is not working correctly. Can someone pl ...

Symfony: Enhancing array elements with updated bootstrap progress bar

I'm facing a challenging issue that I need help with. Currently, I have a command set up to send a large number of emails (around 300 or more) every 5 minutes using cron in order to distribute a newsletter. My goal is to keep track of how many emails ...

Refreshing the package using Bower

I'm facing an issue while trying to upgrade angular from version 1.0.5 to 1.0.6 using Yeoman. Despite clearing the cache and checking the Github repository, it still installs version 1.0.5. Is there a workaround to force the update to version 1.0.6? ...

Error in Angular: Http Provider Not Found

NPM Version: 8.1.4 Encountered Issue: Error: Uncaught (in promise): Error: Error in ./SignupComponent class SignupComponent_Host - inline template:0:0 caused by: No provider for Http! Error: No provider for Http! The error message usually indicates the a ...

The JavaScript function is not functioning properly, whereas another function is working as intended

I have created a HTML form with 2 buttons and a table. Each row in the table consists of a checkbox and 2 text fields. The buttons allow users to add and remove rows from the table. The remove button only applies to rows where their checkbox is checked. T ...

Establishing relationships with Sequelize between tables in different schemas

Currently, I am working on a project that involves using Sequelize and PostgreSQL as the database. In this project, I have implemented dynamic schema creation whenever a new user registers on the website. Specifically, I have a table called user_credentia ...

html form submission error - please refresh

After submitting a form on my page, I keep encountering an error every time I try to refresh the page. I've attempted several solutions that I came across online, but none of them have resolved the issue as I continue to face this error on different ...

Generate unique identifiers to rotate images dynamically on the webpage

My goal is to rotate every image on a page, and while this works with a single image, it only rotates the first one since each ID needs to be unique. I need to find a way to dynamically increment the IDs as they are encountered on the page. Below is what I ...

Every time Jquery tries to retrieve cookies, it consistently returns as undefined

Having trouble accessing Application cookies using jquery in my Asp.Net MVC App. Check out this Screenshot of Cookie and its Value. I've been trying to access the Cookie with $.cookie('ASP.NET_SessionId'); but it keeps returning "undefined" ...

Tips on preventing hardcoded, chained asynchronous functions in JavaScript/jQuery

In my program, almost all functions involve asynchronous calls that rely on the results of previous functions. To manage this, I've hard-coded each subsequent function call within the success callback of the preceding one: function getStuff() { $ ...

Is there a way to prevent a background video from automatically playing whenever the user navigates back to the home page?

Recently, I was given a design that requires a background video to load on the home page. Although I understand that this goes against best practices, the client has approved the design and now I need to come up with a solution. The video is already in pla ...

Efficiently making JQuery Ajax requests using HTTP Basic Authentication

I am currently experiencing challenges with implementing HTTP Basic Authentication in JQuery when communicating with a REST-based server. This server provides responses in both XML and JSON formats, but I have chosen to work with JSON format. Our authoriz ...

Struggling to make button switch in my Spring Boot Application (e.g. from "Add to Cart" to "Remove")

My application allows users to add items to their cart, which are then persisted using Spring Data JPA and saved in a MySQL database. I am looking to change the text from "Add to Cart" to "Remove" when the button is clicked, and vice versa. I have attempt ...

Adjust dimensions of an image retrieved from a URL

Is there a way to adjust the size of the image displayed here?: var picture = new Image(); picture.src = 'http://www.example.com/images/logo.png'; picture.width = 200; //trying to change the width of the image $('canvas').css({ ...

Can you merge multiple req.body requests?

I am exploring a scenario where I have a list of items that need to be iterated through, with each item having the value of i added to it to retrieve the next set of information. For example: By concatenating the string "req.body.item" + i + "Title", you ...

Breadcrumb navigation that is determined by data hierarchies and relationships between parent and child items

I am looking to implement a dynamic breadcrumb system on my website using data-driven methodology. The necessary data is stored in a MariaDB database and has the following structure: parent_id | parent_name | child_id | child_name ——————— ...