我在尝试使用装饰器将 TypeScript 编译为 JavaScript 时遇到了问题。我得到的错误是这样的:
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 { ~~~~~~
我一直在 StackOverflow 中搜索修复它的方法,也在其他网站上搜索,但似乎没有任何方法适合我。这是我已经尝试过的:
- 我的 tsconfig.json 文件中已经有
"experimentalDecorators": true
- 我在设置文件中添加了
"javascript.implicitProjectConfig.experimentalDecorators": true
- 我尝试禁用我所有的 VSCode 扩展
- 我尝试多次重启 VSCode 并以多种方式打开项目文件夹
无论如何,我总是收到同样的错误。我的 TypeScript 版本是 4.1.2
。
编辑:我将我的项目上传到谷歌驱动器 this link .
最佳答案
我建议您再做一件事,您可以通过检查您的 tsconfig.json
来查看它是否包含您的源文件。
我假设您的文件位于:src/index.ts
,因此您可能还需要将其包含
到配置文件中。
tsconfig.json
{
"compilerOptions": {
// ...
"experimentalDecorators": true
},
"include": [
// Include your source file as well
"src"
],
}
如果使用输入文件(您自己的模式)运行
在这种情况下,tsc
不允许您再使用自己的配置,即 tsconfig.json
文件。
因此您需要通过 CLI 指定您的选项,如下所示:
tsc -w '.\src\app.ts' --experimentalDecorators --target es6
关于javascript - 在 Visual Studio Code 中使用装饰器时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65178095/