question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ThenableReference returning PromiseLike - should be Promise?

See original GitHub issue

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<any> ?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
schmidt-sebastiancommented, Mar 20, 2018

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.

1reaction
stevejcoxcommented, Dec 4, 2017

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

typescript - firebase thenable reference return handling
interface ThenableReference extends firebase.database. ... @returns A Promise for the completion of which ever callback is executed.
Read more >
ThenableReference returning PromiseLike - should be Promise?
Coming soon: A brand new website interface for an even better experience!
Read more >
ThenableReference | Firebase JavaScript API reference
Reference for ThenableReference. ... of the remove to the Firebase servers will also be started, and the returned Promise will resolve when complete....
Read more >
https://unpkg.com/firebase@5.0.2/index.d.ts
Reference, PromiseLike<any> {} function enableLogging( logger?: boolean | ((a: ... If this fails, enablePersistence() will reject the promise it returns.
Read more >
PromiseLike | typescript - v3.7.7
Optional onrejected: function | undefined | null. The callback to execute when the Promise is rejected. Returns PromiseLike<TResult1 | TResult2>.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found