Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ThenableReference returning PromiseLike - should be Promise? #144

Closed
stevejcox opened this issue Nov 22, 2017 · 10 comments
Closed

ThenableReference returning PromiseLike - should be Promise? #144

stevejcox opened this issue Nov 22, 2017 · 10 comments
Assignees

Comments

@stevejcox
Copy link

It looks like when the RTDB were put back in with pr: #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 ?

@google-oss-bot
Copy link

Hey there! I couldn't figure out what this issue is about, so I've labeled it for a human to triage. Hang tight.

@google-oss-bot
Copy link

Hmmm this issue does not seem to follow the issue template. Make sure you provide all the required information.

@hiranya911
Copy link
Contributor

PromiseLike is what is used in JS SDK, where the RTDB code actually resides.

@jshcrowthe wdyt?

@stevejcox
Copy link
Author

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?

@jshcrowthe
Copy link

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.

@ezos86
Copy link

ezos86 commented Feb 3, 2018

@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.

@pontius-g
Copy link

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.

@schmidt-sebastian
Copy link
Contributor

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.

@pontius-g
Copy link

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)

@garalimedkarim4
Copy link

garalimedkarim4 commented Sep 8, 2019

.push({...}).then(onsuccess, onfailure)

Yeah This is the Solution (y) Happy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants