【问题标题】:Argument of type 'any[]' is not assignable to parameter of type '(value: [any, Campaign[]]) => void''any[]' 类型的参数不可分配给 '(value: [any, Campaign[]]) => void' 类型的参数
【发布时间】:2019-09-06 18:30:39
【问题描述】:

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

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”并加载活动对象,然后在订阅中我想调用一个模式对话框。但是我收到上述错误 我是打字稿和可观察的新手。

感谢任何帮助 太感谢了 呸呸呸

【问题讨论】:

    标签: angular typescript rxjs rxjs5


    【解决方案1】:

    这是语法问题 我应该这样写

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

    【讨论】:

      猜你喜欢
      • 2021-08-24
      • 2022-01-05
      • 1970-01-01
      • 2020-03-19
      • 2018-03-19
      • 2019-01-09
      • 2023-01-12
      • 2021-12-03
      • 2021-06-10
      相关资源
      最近更新 更多