Skip to content

nextOrObserver:Object type definition in typescript doesn't allow type inference #54

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

Closed
esprehn opened this issue Jun 15, 2017 · 3 comments

Comments

@esprehn
Copy link

esprehn commented Jun 15, 2017

[REQUIRED] Describe your environment

  • Operating System version: OS X
  • Firebase SDK version: 3.6.8
  • Firebase Product: all (noticeable in auth)

[REQUIRED] Describe the problem

The firebase.d.ts file contains the following type definitions:

onAuthStateChanged (nextOrObserver : Object , error ? : (a : firebase.auth.Error ) => any , completed ? : ( ) => any ) : ( ) => any ;

but this means you can't just pass a function like

.onAuthStateChanged((user) => {
 ...
});

and let |user| by in inferred type, because typescript thinks this method takes an Object. If we look at closure externs they're more specific:

* @param {!Object|function(?firebase.User)}

@param {!Object|function(?firebase.User)}

which would let you pass a callback without explicitly naming the type.

Steps to reproduce:

in typescript write:

firebase.auth().onAuthStateChanged((user) => {
  console.log(user);
});

In general the "Observer" concept is mentioned in the API type definitions and docs, but I don't see anything documented about what an Observer object would be. Everything just passes a function here, is that some Firebase internal type?

Ideally the type definitions here would be specific enough that typescript could infer the argument types of all of the callbacks used in all the various firebase apis. :)

@google-oss-bot
Copy link
Contributor

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

@jsayol
Copy link
Contributor

jsayol commented Jun 15, 2017

@esprehn - an observer in this case would be an object with any of the next, error, and complete methods.

You're right, though. The typings should be fixed.

@jshcrowthe
Copy link
Contributor

jshcrowthe commented Jul 6, 2017

This was fixed in #56, thanks @esprehn and @jsayol!

@firebase firebase locked and limited conversation to collaborators Oct 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants