How to configure Vscode to identify private field syntax

Asked

Viewed 289 times

2

I’m testing new JS features, but my Vscode can’t detect that the project uses the new private field syntax. The code is like this:

entities.js

class Person {
    constructor(p = {}) {
        if(p) Object.assign(this, p)
    }

    #id
    get id() { return this.#id }
    set id(v) { this.#id = v }

    #name
    get name() { return this.#name }
    set name(v) { this.#name = v }

    #age
    get age() { return this.#age }
    set age(v) { this.#age = v}
}

Based on the documentation, by using this code I can create a class that:

  • Allows the passage of properties as initial values
  • Allows me to have hidden fields (the fields starting with old game)
  • Enables encapsulation of properties
  • Enables more coherent and clean OO work.

For me to work on the code I’m using Vscode only it can’t read this way of writing and keeps telling me that the code is incorrect:

erro no VSCode que não consegue entender a linguagem

What I need to do to make you understand what I’m writing?

1 answer

3


VS Code currently does not support ES7 and what they suggest in the official documentation itself is to disable the native JS validator and use some extension like Eslint to validate the code. https://code.visualstudio.com/Docs/languages/javascript#_how-do-i-disable-syntax-validation-when-using-nones6-constructs

Some users want to use syntax constructs like the proposed pipeline (|>) Operator. However, These are Currently not supported by VS Code’s Javascript language service and are flagged as errors. For users who still want to use These Future Features, we provide the javascript.validate.enable Setting.

Translating: "Some users wish to use syntax constructs as the proposed pipeline operator (|>). However, they are not currently supported by the VS Code Javascript language service and are flagged as errors. For users who still want to use these future features, we provide configuration javascript.validate.enable."

With javascript.validate.enable: false, you disable all internal syntax checks. If you do this, we recommend using a linter like the Eslint to validate your source code. Since VS Code Javascript support does not understand ES7 constructs, features such as Intellisense may not be fully accurate.

Eslint: https://eslint.org/

VS Conde marketplace with extensions that can help you: https://marketplace.visualstudio.com/search?term=eslint&target=VSCode&category=All%20categories&sortBy=Relevance

Browser other questions tagged

You are not signed in. Login or sign up in order to post.