最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Errors when using decorators in Visual Studio Code - Stack Overflow

programmeradmin5浏览0评论

I've been having issues trying to pile 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.

I've been having issues trying to pile 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.

Share Improve this question edited Dec 14, 2020 at 10:52 Enrico Cortinovis asked Dec 7, 2020 at 8:14 Enrico CortinovisEnrico Cortinovis 8713 gold badges11 silver badges34 bronze badges 4
  • Your VS code can use different version of TS. Please double check in right bottom corner of VS code, which version of TS VS code uses – captain-yossarian from Ukraine Commented Dec 7, 2020 at 8:32
  • @captain-yossarian It says 4.0.3. – Enrico Cortinovis Commented Dec 7, 2020 at 8:46
  • Click on 4.0.3 and select 4.1.2 – captain-yossarian from Ukraine Commented Dec 7, 2020 at 8:48
  • @captain-yossarian I don't get that option. I can only select: "Open tsconfig", "Select TypeScript Version ... 4.0.3" and "TypeScript help". The 4.1.2 version is what I got by typing tsc -v in the terminal. – Enrico Cortinovis Commented Dec 7, 2020 at 8:51
Add a ment  | 

3 Answers 3

Reset to default 6 +50

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

{
  "pilerOptions": {
    // ...
    "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.

发布评论

评论列表(0)

  1. 暂无评论