javascript - Angular 2 引导函数给出错误 "Argument type AppComponent is not assignable to parameter type Type"

标签 javascript angular typescript intellij-idea

这是我的第一个简单的 Hello World angular 2 应用程序,来自 Angular 2 quick start guide .

import {Component} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser';
@Component({
    selector: 'ng2-app',
    template: '<h1>My first Angular 2 App</h1>'
})
export class AppComponent { }


bootstrap(AppComponent);

当我使用 npm start 运行时,应用程序运行正常,但我的 IntelliJ IDE 在 bootstrap(AppComponent) 行中显示错误

Argument type AppComponent is not assignable to parameter type Type

Angular 2 typescript warning

查看bootstrap 函数声明,AppComponent 需要扩展Type

export declare function bootstrap(appComponentType: Type, customProviders?: Array<any>): Promise<ComponentRef>;

我的问题是:

是否期望 Angular 组件扩展 Type

最佳答案

我在 Intellij 2016.1.2 中通过 Angular 快速入门演示偶然发现了这一点。在 IDE 中设置以下选项有帮助:

enter image description here

关于javascript - Angular 2 引导函数给出错误 "Argument type AppComponent is not assignable to parameter type Type",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34366797/

相关文章:

javascript - 递归更新一个值到顶部的方法

javascript - 具有特定锚定文本值的 AngularJS 搜索/查找/过滤 div

angular - *ngIf 替代以 Angular 2 设置按钮文本?

html - 找不到名称为 : 'email' in angular 的控件

Angular Jest 旁观者在测试另一个服务时模拟服务依赖性

javascript - 在这种情况下是否有更好的 RXJs Operator 可以使用?

javascript - 多个月禁止在选择时移动到第一个

javascript - Jquery JSON解码多个数组

angular - 如何从 Firebase 检索数据以传递到 angularfire2/version-5 中的数组

javascript - typescript + react : defining defaultProps correctly