[英]Errors when using decorators in Visual Studio Code
I've been having issues trying to compile TypeScript to JavaScript when using decorators.在使用装饰器时,我在尝试将 TypeScript 编译为 JavaScript 时遇到问题。 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. app.ts:11:7 - 错误 TS1219:对装饰器的实验性支持是一项可能在未来版本中更改的功能。 Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning.在“tsconfig”或“jsconfig”中设置“experimentalDecorators”选项以删除此警告。
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.我一直在 StackOverflow 和其他网站上搜索修复它的方法,但似乎没有什么对我有用。 Here's what I've already tried:这是我已经尝试过的:
"experimentalDecorators": true
in my tsconfig.json file我的tsconfig.json文件中已经有了"experimentalDecorators": true
"javascript.implicitProjectConfig.experimentalDecorators": true
in my settings file我在我的设置文件中添加了"javascript.implicitProjectConfig.experimentalDecorators": true
I keep getting this same error anyways.无论如何,我一直收到同样的错误。 My TypeScript version is 4.1.2
.我的 TypeScript 版本是4.1.2
。
Edit: I uploaded my project to google drive at this link .编辑:我通过此链接将我的项目上传到谷歌驱动器。
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.我建议您可以通过检查您的tsconfig.json
来尝试另一件事,看看这是否包含您的源文件。
I assume your file is located in under: src/index.ts
, so you might also need to include
it in the configuration file.我假设您的文件位于: src/index.ts
下,因此您可能还需要将其include
在配置文件中。
tsconfig.json
{
"compilerOptions": {
// ...
"experimentalDecorators": true
},
"include": [
// Include your source file as well
"src"
],
}
In this case tsc
doesn't allow you to use your own config anymore which is tsconfig.json
file.在这种情况下, tsc
不再允许您使用自己的配置,即tsconfig.json
文件。
So you need to specify your options via the CLI as following:因此,您需要通过 CLI 指定您的选项,如下所示:
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
.在 VSCode go 到preferences -> settings
,在搜索设置输入中键入javascript
,然后您将看到Javascript > Implicit Project Config: Experimental Decorators
的选项Check it and save the settings file.检查它并保存设置文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.