Typescript Ts—类型参数';TResult1';无法从用法中推断
我有以下承诺:Typescript Ts—类型参数';TResult1';无法从用法中推断,typescript,rxjs,Typescript,Rxjs,我有以下承诺: this.personService.getPerson(this.person.id).toPromise() .then((person) => this.getAddress(person)) .then(() => this.save()) .catch(() => this.handle) 此.getAddress(person)返回AddressListDto 这个.save
this.personService.getPerson(this.person.id).toPromise()
.then((person) => this.getAddress(person))
.then(() => this.save())
.catch(() => this.handle)
此.getAddress(person)返回AddressListDto
这个.save()返回void
我得到了这个错误:
无法从用法推断类型参数“TResult1”的类型参数。考虑显式指定类型参数。
类型参数候选“void”不是有效的类型参数,因为它不是候选“AddressListDto”的超类型
从您的代码:
this.personService.getPerson(this.person.id).toPromise()
.then((person) => this.getAddress(person))
.then(() => this.save())
.catch(() => this.handle)
返回类型还包括this.handle是什么。处理错误的一种方法
this.personService.getPerson(this.person.id).toPromise()
.then((person) => this.getAddress(person))
.then(() => this.save())
.catch((e) => {
console.log("Optional tracking", e);
throw e;
})
更多
无论如何,您可能想调用
handle
。它看起来像this.getAddress()
或this.save()
returnvoid
(或者您忘记了返回任何内容)this.getAddress()返回和AddressListDto,而这个.save()返回void可能就是问题所在.then()
支持链接,因此当您返回void
时,任何其他then()
调用都不会收到任何内容。请查看lib.es6.d.ts
,其中then()
在Promise
类中定义为:then(…):Promise
。