Skip to content

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

@esprehn

Description

@esprehn

[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. :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions