类型'MonoTypeOperatorFunction <any []>'不能分配给类型'OperatorFunction <message,any [] =“”>

时间:2019-01-28 16:21:26

标签: angular rxjs angular6

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

  src / app / app.component.ts(68,7)中的

ERROR:错误TS2345:的参数   类型'MonoTypeOperatorFunction'不可分配给参数   类型为“ OperatorFunction”。参数类型   “源”和“源”不兼容。       类型“可观察”不能分配给类型“可观察”。         不能将“消息”类型分配给“任何[]”类型。           类型“消息”中缺少属性“长度”。

我的组件是它

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], [])

1 个答案:

答案 0 :(得分:1)

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

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

另请参阅:https://github.com/ReactiveX/rxjs/pull/2897#issuecomment-334654459