首页 文章

Aurelia事件聚合器示例代码subscribe()是无效的Typescript?

提问于
浏览
0

Aurelia主站点上的联系人管理器教程显示,对于名为ea的EventAggregator实例,可以在TypeScript中使用以下代码订阅发布:

ea.subscribe(ContactViewed, msg => this.select(msg.contact));

但是,尽管正确定义了所需的ContactViewed类,但此语法不会在VS 2017中“编译”(将警告配置为错误) .

Error TS2346 (TS) Supplied parameters do not match any signature of call target.

幸运的是,以下“等效”语法确实可以编译和工作:

ea.subscribe(ContactViewed, function(msg: ContactViewed) {
        this.select(msg.contact);
    });

所以我的问题是,为什么这个语法被Aurelia记录为有效的TypeScript,和/或为什么它对我不起作用?

谢谢

1 回答

  • 0

    我能用一些括号和类型指令纠正这个问题:

    ea.subscribe(ContactViewed, (msg: ContactViewed) => this.select(msg.contact));
    

    我当然是Aurelia和Typescript的新手,但是当“供应商”文档提供的教程信息无法开箱即用时,它会变得更加困难 . 学过的知识 .

相关问题