Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VS代码-Angular:对装饰程序警告的实验支持_Angular_Typescript_Visual Studio Code - Fatal编程技术网

VS代码-Angular:对装饰程序警告的实验支持

VS代码-Angular:对装饰程序警告的实验支持,angular,typescript,visual-studio-code,Angular,Typescript,Visual Studio Code,在Angular(v10)项目中,创建一个空白文件(sync.service.ts)并添加以下代码: import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root' }) export class SyncService { } 给出以下警告: Experimental support for decorators is a feature that is subject to change

在Angular(v10)项目中,创建一个空白文件(sync.service.ts)并添加以下代码:

import { Injectable } from '@angular/core';

@Injectable({
    providedIn: 'root'
})
export class SyncService {

}
给出以下警告:

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.
我打开了一个随机文件(tag cloud.component.ts)并添加了一条导入语句:

import { SyncService } from '../../services/sync.service';
警告消失了。但是警告消息根本不应该出现,因为:

@Injectable({
    providedIn: 'root'
})
请看下面的gif。这是虫子吗


这是我在WebStorm中遇到的一种奇怪的行为。我所能说的是,过了一段时间(无法告诉您是什么触发IDE正确理解),警告消失,一切恢复正常。

出现“问题”是因为Typescript 3.9和Angular 10附带的Tconfig文件(解决方案样式Tconfig)发生了更改

更多信息请点击此处:

解决方案样式t配置角度10的影响

在TypeScript 3.9中,解决方案样式tsconfig的概念是 在介绍中,我们看到了 修复长期未解决的问题,例如错误地进行测试键入 在组件文件中。在Angular CLI版本10中,我们采用了脚手架 新建和迁移现有工作区以使用解决方案样式的Typescript 配置

当有一个未引用的文件时,这将不是任何 TypeScript程序,这是因为Angular CLI支持tsconfig 使用文件选项而不是包含和排除

  • 未引用的文件不会继承编译器选项

    当有一个未引用的文件时,这将不是任何TypeScript程序的一部分 语言服务将回退以使用推断的项目配置

    下面是应用程序中所需更改的示例 tsconfig文件(tsconfig.app.json)。对其他tsconfig文件的更改也将被删除 这是需要的

  • 当前tsconfig.app.json

    {
     "extends": "./tsconfig.base.json",
     "compilerOptions": {
       ...
     },
     "files": [
       "src/main.ts",
       "src/polyfills.ts"
     ],
     "include": [
       "src/**/*.d.ts"
     ]
    }
    
    {
     "extends": "./tsconfig.base.json",
     "compilerOptions": {
       ...
     },
     "include": [
       "src/**/*.ts"
     ],
     "exclude": [
       "src/test.ts",
       "src/**/*.spec.ts",
       "src/**/*.server*",
       "src/**/*.worker.ts"
     ]
    }
    
    建议的tsconfig.app.json

    {
     "extends": "./tsconfig.base.json",
     "compilerOptions": {
       ...
     },
     "files": [
       "src/main.ts",
       "src/polyfills.ts"
     ],
     "include": [
       "src/**/*.d.ts"
     ]
    }
    
    {
     "extends": "./tsconfig.base.json",
     "compilerOptions": {
       ...
     },
     "include": [
       "src/**/*.ts"
     ],
     "exclude": [
       "src/test.ts",
       "src/**/*.spec.ts",
       "src/**/*.server*",
       "src/**/*.worker.ts"
     ]
    }
    

    有趣的是,其他IDE也给出了这个警告。所以它很可能与VS代码无关。你说得对,其他服务(与此类似,但之前创建的)没有此问题。你是否向Tconfig文件添加了实验装饰器?没有,我没有接触Tconfig文件。这应该是设置值:
    “experimentalDecorators”:true
    刚刚选中,它设置为“true”。该项目是最近使用“ng new”创建的。请尝试重新启动TypeScript服务器:
    F1->TypeScript:Restart TS Server