【问题标题】:Argument of type 'NgElementConstructor<unknown>' is not assignable to parameter of type 'CustomElementConstructor'“NgElementConstructor<unknown>”类型的参数不能分配给“CustomElementConstructor”类型的参数
【发布时间】:2020-06-23 07:19:07
【问题描述】:

在使用 Angular9 创建 Angular 元素时,我在 VSCode(1.44.0-insider) 中收到了一个奇怪的警告:

export class AppModule { 
  constructor(private injector: Injector) {
    const helloElement = createCustomElement(HelloComponent, {injector});
    customElements.define('my-hello', helloElement);
  }
  ngDoBootstrap() {}
}

helloElement 的类型不被接受,并带有来自 typescript 的错误消息:

“NgElementConstructor”类型的参数不能分配给“CustomElementConstructor”类型的参数

【问题讨论】:

    标签: angular visual-studio-code angular-elements


    【解决方案1】:

    看来下个版本会修复它:https://github.com/angular/angular/pull/35864

    您已经可以通过更新到下一个版本 (9.1.0-next.4) 为您的项目测试它。

    ng update @angular/core --next 
    

    【讨论】:

    • 使用“ng update @angular/cli @angular/core”来避免安装的包与更新不兼容时出现错误。
    猜你喜欢
    • 1970-01-01
    • 2020-07-24
    • 1970-01-01
    • 1970-01-01
    • 2021-11-11
    • 1970-01-01
    • 2019-02-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多