类型'any []'的参数不能分配给'(value:[any,Campaign []])=> void'类型的参数

问题描述 投票:0回答:1

嗨我在我的代码中收到打字稿错误。以下是我的代码。

combineLatest(
          this.translateService.get('CLONE_FLIGHT', { item: this.flight.name}),
          this.flightsService.getCampaignsToClone(this.flight.id)
        ).subscribe([  header, campaigns]) => { 
          console.log('test');
        });

我收到的错误是

Argument of type 'any[]' is not assignable to parameter of type '(value: [any, Campaign[]]) => void'.
  Type 'any[]' provides no match for the signature '(value: [any, Campaign[]]): void'.ts(2345)
Cannot find name 'campaigns'.ts(2304)

translateService.get的方法签名如下

get(key: string | Array<string>, interpolateParams?: Object): Observable<string | any>;

方法调用flightsService.getCampaignsToClone(this.flight.id)

getCampaignsToClone(flightId: string){
    let campaigns: Campaign[] = [
      {  id:"1", name: "test campaign 001", createdOn:"",lastUpdated: "", createdBy: null,
      type:null, status: null, startDate: null, endDate: null, budget: null, description: "",
      account: null },
      {  id:"2", name: "test campaign 002", createdOn:"",lastUpdated: "", createdBy: null,
      type:null, status: null, startDate: null, endDate: null, budget: null, description: "",
      account: null },
      {  id:"3", name: "test campaign 003", createdOn:"",lastUpdated: "", createdBy: null,
      type:null, status: null, startDate: null, endDate: null, budget: null, description: "",
      account: null }
     ];
    return Observable.of(campaigns);

  }

我想要实现的代码是首先解析属性'CLONE_FLIGHT'并加载广告系列对象,然后在订阅中我想调用一个模态对话框。但是我得到上面的错误我是打字稿和观察者的新手。

感谢任何帮助非常感谢prasanth

angular typescript rxjs rxjs5
1个回答
0
投票

这是我应该写的语法问题

combineLatest(
  this.translateService.get('CLONE_FLIGHT', { item: this.flight.name}),
  this.flightsService.getCampaignsToClone(this.flight.id)
).subscribe( ([header, campaigns]) => { 
  console.log(header);
});
© www.soinside.com 2019 - 2024. All rights reserved.