angular - 类型 'MonoTypeOperatorFunction<any[]>' 不可分配给类型为“OperatorFunction<Message, any[]>”的参数

标签 angular rxjs angular6

我正在尝试进行剑道聊天示例:https://www.telerik.com/kendo-angular-ui/components/conversationalui/
我使用 Visual Studio 代码和 angular 6,我在谷歌搜索但找不到解决方案
但我收到了这个错误:

ERROR in src/app/app.component.ts(68,7): error TS2345: Argument of type 'MonoTypeOperatorFunction' is not assignable to parameter of type 'OperatorFunction'. Types of parameters 'source' and 'source' are incompatible. Type 'Observable' is not assignable to type 'Observable'. Type 'Message' is not assignable to type 'any[]'. Property 'length' is missing in type 'Message'.



我的组件是:
import { Component } from '@angular/core';    
import { Subject } from 'rxjs/Subject';
import { switchMap } from 'rxjs/operators/switchMap';
import { map } from 'rxjs/operators/map';
import { windowCount } from 'rxjs/operators/windowCount';
import { scan } from 'rxjs/operators/scan';
import { take } from 'rxjs/operators/take';
import { tap } from 'rxjs/operators/tap';
import { from } from 'rxjs/observable/from';
import { merge } from 'rxjs/observable/merge';

import { ChatModule, Message, User, Action, ExecuteActionEvent, SendMessageEvent } from '@progress/kendo-angular-conversational-ui';
import { Observable } from 'rxjs/Observable';
import { ChatService } from './chat.service';

@Component({
  providers: [ ChatService ],
  selector: 'my-app',
  template: `
      <kendo-chat
        [messages]="feed | async"
        [user]="user"
        (sendMessage)="sendMessage($event)"
      >
      </kendo-chat>
    `
})
export class AppComponent {
  public feed: Observable<Message[]>;

  public readonly user: User = {
    id: 1
  };

  public readonly bot: User = {
    id: 0
  };

  private local: Subject<Message> = new Subject<Message>();

  constructor(private svc: ChatService) {
    const hello: Message = {
      author: this.bot,
      suggestedActions: [{
        type: 'reply',
        value: 'Neat!'
      }, {
        type: 'reply',
        value: 'Thanks, but this is boring.'
      }],
      timestamp: new Date(),
      text: 'Hello, this is a demo bot. I don\t do much, but I can count symbols!'
    };

    // Merge local and remote messages into a single stream
    this.feed = merge(
      from([ hello ]),
      this.local,
      this.svc.responses.pipe(
        map((response): Message => ({
          author: this.bot,
          text: response
        })
      ))
    ).pipe(
      // ... and emit an array of all messages
      scan((acc, x) => [...acc, x], [])
    );
  }

  public sendMessage(e: SendMessageEvent): void {
    this.local.next(e.message);

    this.local.next({
      author: this.bot,
      typing: true
    });

    this.svc.submit(e.message.text);
  }
}

我收到错误的行代码是:
scan((acc, x) => [...acc, x], [])

最佳答案

我也遇到了具体问题。尝试以下修复:

scan((acc:any, x) => acc.concat(x), [])

另见:https://github.com/ReactiveX/rxjs/pull/2897#issuecomment-334654459

关于angular - 类型 'MonoTypeOperatorFunction<any[]>' 不可分配给类型为“OperatorFunction<Message, any[]>”的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54406225/

相关文章:

angular - 每个新的 Angular 生产PWA版本上的“意外 token <”,直到站点刷新

html - 使用<template ngFor>代替* ngFor时出现奇怪的间隙

angular - 如何订阅 Angular 6 中不同模块输入的值变化?

Angular 转换 HttpClient 响应 - 类或接口(interface)

html - 有没有办法突出显示点击的 mat-grid-tile?当动态生成每个 mat-grid-tile 时

angular - 拒绝从 URL 执行脚本,因为其 MIME 类型 ('application/json' ) 不可执行,并且启用了严格的 MIME 类型检查

html - 输入字段的必需属性不起作用且输入字段颜色未更改

angular - 如何在 RxJs Observable 构造函数中使用异步调用

javascript - 为什么 Angular 2 的 CanActivate 返回 Observable<boolean> 而不是 Promise?

angular - Redux 初始状态在 Angular 中充满空值