Visual Studio Code 'const' can only be used in a .ts file

Viewed 19155

I am getting this error while trying a write a basic JS in Visual Studio Code.

Already tried changing the settings.json ( $workspace/.vscode/settings.json ) but it doesn't work.

  {
     "javascript.validate.enable": false
  }

enter image description here

2 Answers

Afaik, You can't define static const within the class declaration. you can try something like this

const MAX_WIDTH = 8.5;

class Books {
  get MAX_WIDTH() {
    return MAX_WIDTH;
  }
}

let myBooks = new Books()
alert(myBooks.MAX_WIDTH);

Related