Errors when using decorators in Visual Studio Code

Viewed 1322

I've been having issues trying to compile TypeScript to JavaScript when using decorators. The error I get is this:

app.ts:11:7 - error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning.

11 class Person {
         ~~~~~~

I've been searching here in StackOverflow for ways to fix it, and also on other websites, and nothing seemed to work for me. Here's what I've already tried:

  • I already have "experimentalDecorators": true in my tsconfig.json file
  • I added "javascript.implicitProjectConfig.experimentalDecorators": true in my settings file
  • I tried disabling all my VSCode extensions
  • I tried restarting VSCode multiple times and opening the project folders in multiple ways

I keep getting this same error anyways. My TypeScript version is 4.1.2.

Edit: I uploaded my project to google drive at this link.

3 Answers

I would suggest one more thing you could try by checking your tsconfig.json to see if this does include your source file or not.

I assume your file is located in under: src/index.ts, so you might also need to include it in the configuration file.

tsconfig.json

{
  "compilerOptions": {
    // ...
    "experimentalDecorators": true
  },
  "include": [
    // Include your source file as well
    "src"
  ],
}

In case of running with input file (your own pattern)

In this case tsc doesn't allow you to use your own config anymore which is tsconfig.json file.

So you need to specify your options via the CLI as following:

tsc -w '.\src\app.ts' --experimentalDecorators --target es6

add setting

{
  ...
  "js/ts.implicitProjectConfig.experimentalDecorators": true,
  ...
}

In VSCode go to preferences -> settings, type javascript in search settings input and then you will see an option to Javascript > Implicit Project Config: Experimental Decorators. Check it and save the settings file.

Related