14

我刚刚从 github 克隆了 angular2-seed 项目并按照步骤操作,但我在 VS 代码中收到了这个警告 [ts] 对装饰器的实验性支持是一项在未来版本中可能会更改的功能。设置“实验装饰器”选项以删除此警告。

4

10 回答 10

18

在我创建的新服务上使用 @Injectable() 时遇到了这个问题。我收到了来自 VS Code 的打字稿编译器的警告。

当我将该新服务作为提供者添加到我打算使用它的模块时,警告消失了。

希望这可以解决您的问题。

于 2017-12-13T15:51:48.907 回答
15

在 Visual Studio 代码中转到File -> Preferences -> Settings并检查Experimental Decorators

在此处输入图像描述

于 2020-09-16T14:22:23.793 回答
15

转到vscode中的文件/首选项/用户设置,把这段代码

{
  "typescript.tsdk": "node_modules/typescript/lib"
}
于 2016-10-09T21:38:31.253 回答
6

在您的tsconfig.json文件中,将项目的路径添加到include属性中,如下所示:

"include": [
    "app/**/*"
]

或者,您可以将单个文件添加到files属性中。以下是我tsconfig.json的示例(对于 Angular2 应用程序):

{
    "compileOnSave": false,
    "buildOnSave": false,
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "moduleResolution": "node",
        "removeComments": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "noEmitHelpers": true,
        "sourceMap": true,
        "types": [
            "node"
        ],
        "typeRoots": [
            "../node_modules/@types"
        ],
        "lib": [
            "es2015",
            "dom"
        ]
    },
    "files": [
        "app/main.ts",
        "app/app.module.ts"
    ],
    "include": [
        "app/**/*.ts"
    ],
    "exclude": [
        "node_modules",
        "dist",
        "build",
        "app/main.aot.ts"
    ]
}
于 2017-01-20T19:55:23.143 回答
2

你的 tsconfig.json 应该是这样的:

{
    "compilerOptions": {
        "experimentalDecorators": true
    },
    "files": [],     //add a "files" array (in my case empty)
    "exclude": [
        "node_modules"
    ]
}

或者,您可以在 VSCode 首选项(用户设置)中添加一行

"javascript.implicitProjectConfig.experimentalDecorators": true
于 2018-05-25T11:45:38.103 回答
1

在 VS Code 设置中找到“experimentalDecorators”。这将列出 Extension->TypeScript 与属性 JavaScript-> Implicit Project Config -> Experimental Decorators 启用此设置将解决警告

于 2020-06-25T11:09:03.273 回答
1

在 VS Code 中,打开settings.json并添加以下行:

"javascript.implicitProjectConfig.experimentalDecorators": true

于 2020-07-25T21:56:42.333 回答
0

我使用这样的命令解决了类似的问题

tsc .\app.ts --experimentalDecorators --target es6

其中 .\app.ts 是文件的路径

于 2021-11-14T15:34:55.417 回答
0

我在新添加的类的 VS Code 中收到此警告。项目编译没有任何错误。当我开始通过import警告引用新添加的类时,就会出现。

在这种情况下,无需更改 VS Code 或 Typescript 中的配置。

于 2021-06-24T12:56:53.710 回答
0

这是由于使用了旧版本的打字稿。您必须升级您的 typescript 版本才能删除此消息。

npm install -g typescript@latest

此外,您还需要将您的 npm 升级到最新版本。

于 2016-09-28T16:33:41.580 回答