嗨,我在代码中收到打字稿错误。以下是我的代码。
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>;
方法调用flightService.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”并加载Campaigns对象,然后在订阅中我要调用模式对话框。但是我收到上述错误 我是打字稿和Observables的新手。
感谢任何帮助 非常感谢 天竺葵
答案 0 :(得分:0)
这是语法问题 我应该这样写
combineLatest(
this.translateService.get('CLONE_FLIGHT', { item: this.flight.name}),
this.flightsService.getCampaignsToClone(this.flight.id)
).subscribe( ([header, campaigns]) => {
console.log(header);
});