编译包含 Angular2 导入的 Typescript 时在 Webstorm 中获取警告
Getting warnings in Webstorm when compiling Typescript that contained Angular2 imports
我刚刚从这里举了个例子https://angular.io/guide/quickstart
我已经按照快速入门手册完成了所有操作。
但是当我的 app.ts
正在编译时,在 WebStorm 控制台中收到警告。
详情如下:
我在 Windows 8.1 x64,Webstorm 11.0.1
app.ts
:
import {bootstrap, Component} from 'angular2/angular2';
@Component({
selector: 'my-app',
template: '<h1>My First Angular 3 App</h1>'
})
class AppComponent { }
bootstrap(AppComponent);
tsconfig.json
:
{
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"sourceRoot": "/"
},
"exclude": [
"node_modules"
]
}
我将 tsconfig.json
文件放在 app
文件夹和根目录中。
app.ts
实际上正在编译文件,但由于某种原因收到警告:
error TS1148: Cannot compile modules unless the '--module' flag is provided.
error TS2307: Cannot find module 'angular2/angular2'.
error TS1205: Decorators are only available when targeting ECMAScript 5 and higher.
error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning.
我已经包含了打字
我的文件夹结构
编辑:
在设置中设置 tsconfig.json
后,错误从 Typescript
window
中消失
但在 Run
输出和代码编辑器中出现错误:
tsconfig.json
没有问题:
更新:
文件 -> 设置 -> 语言和框架 -> TypeScript 帮助切换到 tsconfig.json
。然后我通过禁用之前手动启用的 Typescript 观察器解决了下一个问题:文件 -> 设置 -> 工具 -> 文件观察器。现在有了这些设置,一切正常。
您需要进入 Webstorm 中的文件 -> 设置。然后在设置侧边栏上转到语言和框架 -> TypeScript。
然后在 TypeScript 设置页面中有一个单选按钮选项 Set options manually
或 Use tsconfig.json
。 Select tsconfig 选项,然后应用更改并关闭。然后 webstorm 应该知道在编译 TypeScript 时使用 tsconfig 选项。
我刚刚从这里举了个例子https://angular.io/guide/quickstart
我已经按照快速入门手册完成了所有操作。
但是当我的 app.ts
正在编译时,在 WebStorm 控制台中收到警告。
详情如下:
我在 Windows 8.1 x64,Webstorm 11.0.1
app.ts
:
import {bootstrap, Component} from 'angular2/angular2';
@Component({
selector: 'my-app',
template: '<h1>My First Angular 3 App</h1>'
})
class AppComponent { }
bootstrap(AppComponent);
tsconfig.json
:
{
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"sourceRoot": "/"
},
"exclude": [
"node_modules"
]
}
我将 tsconfig.json
文件放在 app
文件夹和根目录中。
app.ts
实际上正在编译文件,但由于某种原因收到警告:
error TS1148: Cannot compile modules unless the '--module' flag is provided.
error TS2307: Cannot find module 'angular2/angular2'.
error TS1205: Decorators are only available when targeting ECMAScript 5 and higher.
error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning.
我已经包含了打字
我的文件夹结构
编辑:
在设置中设置 tsconfig.json
后,错误从 Typescript
window
但在 Run
输出和代码编辑器中出现错误:
tsconfig.json
没有问题:
更新:
文件 -> 设置 -> 语言和框架 -> TypeScript 帮助切换到 tsconfig.json
。然后我通过禁用之前手动启用的 Typescript 观察器解决了下一个问题:文件 -> 设置 -> 工具 -> 文件观察器。现在有了这些设置,一切正常。
您需要进入 Webstorm 中的文件 -> 设置。然后在设置侧边栏上转到语言和框架 -> TypeScript。
然后在 TypeScript 设置页面中有一个单选按钮选项 Set options manually
或 Use tsconfig.json
。 Select tsconfig 选项,然后应用更改并关闭。然后 webstorm 应该知道在编译 TypeScript 时使用 tsconfig 选项。