gpt4 book ai didi

typescript - 错误 : Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning

转载 作者:行者123 更新时间:2023-12-03 18:44:08 34 4
gpt4 key购买 nike

我正在尝试让一个基本的装饰器示例在 TypeScript 中工作而没有任何运气。

我不断看到错误消息:

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.



我的 tsconfig.json 如下所示(tsconfig 在与 index.ts 相同的文件夹中):
{
"compilerOptions": {
"target": "esnext",
"watch": true,
"experimentalDecorators": true,
}
}

这似乎是一个非常流行的问题,并已在 SO e 上多次询问。 g.: Experimental decorators warning in TypeScript compilation

我已经尝试了所有的解决方案,但没有运气。另外,我的问题似乎与 vscode 无关。尝试从 shell 运行文件时遇到相同的错误。

到目前为止我尝试过的:
  • 重启 VC 代码
  • EmitDecoratorMetaData: true
  • 允许实验装饰器作为 VC 代码中的隐式配置
    在 VC 代码中
  • 手动设置 TS 版本
  • 创建新的 tsconfig.json


  • 编辑

    索引.ts
    function f(): any {
    console.log("f(): evaluated");
    return function (target, propertyKey: string, descriptor: PropertyDescriptor) {
    console.log("f(): called");
    }
    }

    function g(): any {
    console.log("g(): evaluated");
    return function (target, propertyKey: string, descriptor: PropertyDescriptor) {
    console.log("g(): called");
    }
    }

    class C {
    @f()
    @g()
    method() {}
    }

    最佳答案

    我注意到 VS Code 在设置中有一个选项可以为不属于项目的文件启用 experimentalDecorators。你的代码文件是你项目的一部分吗? VS Code Experimental Decorators Screenshot

    关于typescript - 错误 : Set the 'experimentalDecorators' option in your 'tsconfig' or 'jsconfig' to remove this warning,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61341444/

    34 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com