admin管理员组文章数量:1323707
I have the following code:
this.afDb.list('/demo').push({a: 'b'})
.then(_ => console.log('works'))
.catch(err => console.log('err: ', err));
I get the following error on 'catch':
[ts] Property 'catch' does not exist on type 'PromiseLike<any>'.
Seems like a AngularFire2 bug?
I have the following code:
this.afDb.list('/demo').push({a: 'b'})
.then(_ => console.log('works'))
.catch(err => console.log('err: ', err));
I get the following error on 'catch':
[ts] Property 'catch' does not exist on type 'PromiseLike<any>'.
Seems like a AngularFire2 bug?
Share Improve this question edited Jan 27, 2018 at 0:41 Frank van Puffelen 600k85 gold badges889 silver badges859 bronze badges asked Jan 27, 2018 at 0:13 flipcodeflipcode 6712 gold badges10 silver badges20 bronze badges1 Answer
Reset to default 9The error is reported because the PromiseLike
interface in typescript lacks a catch
method. This is consistent with the definition of a "thenable" as an object with a then
method.
interface PromiseLike { /** * Attaches callbacks for the resolution and/or rejection of the Promise. * @param onfulfilled The callback to execute when the Promise is resolved. * @param onrejected The callback to execute when the Promise is rejected. * @returns A Promise for the pletion of which ever callback is executed. */ then(onfulfilled?: ((value: T) => TResult1 | PromiseLike) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike) | undefined | null): PromiseLike; }
is how it's defined in lib.es2015.promise.d.ts on gitHub, starting at line 1291. (The linked HTML page is 5.5MB in size - it may take a while.)
Bear in mind too that the A5+ spec doesn't mention a catch
method, and ES6 (ECMAScript 2015) promises provide catch
as a Promise.prototype
function that simply calls then
with the first argument of catch
as the second argument of then
.
The easiest solution may be to use a two parameter then
call:
this.afDb.list('/demo').push({a: 'b'})
.then(_ => console.log('works'),
err => console.log('err: ', err));
or expand the code for Promise.prototype.catch
into a then
call:
this.afDb.list('/demo').push({a: 'b'})
.then(_ => console.log('works'))
.then( null, err => console.log('err: ', err)); // catch
本文标签: javascriptProperty 39catch39 does not exist on type 39PromiseLikeltanygt39Stack Overflow
版权声明:本文标题:javascript - Property 'catch' does not exist on type 'PromiseLike<any>' - Stack Ov 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742130401a2422131.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论