It looks like when the RTDB were put back in with pr: https://github.com/firebase/firebase-admin-node/pull/140 the interface of ThenableReference changed form extending Promise<any> to PromiseLike<any>.
Is there a reason for this?
PromiseLike does not include a catch declaration for typescript - and so is causing an error. I believe this should be Promise
Hey there! I couldn't figure out what this issue is about, so I've labeled it for a human to triage. Hang tight.
Hmmm this issue does not seem to follow the issue template. Make sure you provide all the required information.
PromiseLike is what is used in JS SDK, where the RTDB code actually resides.
@jshcrowthe wdyt?
Just following up on this, @jshcrowthe - push() seems to return a ThenableReference rather than a Promise. Is there a reason for this? ThenableReference doesn't have declarations for catch, so not totally sure why it wouldn't be a Promise too?
I am probably the wrong guy for the "why?" question here. I'll reassign to @schmidt-sebastian who can probably give us a better clue of what is going on.
@stevejcox
I notice this too. If I push a null value into a location. I don't get a .catch(function(error)} - even though firebase couldn't make the insert into the DB. in the browser, it would return a console error, but the node SDK just treats the .then not a .catch.
When we use .catch() for .push() - SDK tells we're wrong!
When we don't - debugger tells - we didn't .catch() an error from Promise!
Think, it's better for push() to become a promise...
Or please, offer more elegant suggestion.
The ES6 type definition for PromiseLike is as follows:
interface PromiseLike<T> {
/**
* 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 completion of which ever callback is executed.
*/
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): PromiseLike<TResult1 | TResult2>;
}
This is a little hard to read, but it basically states that you can register an error callback as the second argument to your .then() callback. You can try something like this:
.push({...}).then(onsuccess, onfailure)
Note that the RTDB JS SDK uses PromiseLike in some cases to keep backwards compatibility.
Thanks a lot, my bad to not following a reference.
I'll try your solution instead of "temporary .push() replacement" - .set(this.db.createPushId(), data)
.push({...}).then(onsuccess, onfailure)
Yeah This is the Solution (y) Happy!
Most helpful comment
The ES6 type definition for PromiseLike is as follows:
This is a little hard to read, but it basically states that you can register an error callback as the second argument to your .then() callback. You can try something like this:
Note that the RTDB JS SDK uses PromiseLike in some cases to keep backwards compatibility.