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

Firebase typings not compatible with strictFunctionTypes in TypeScript 2.6 #291

Closed
cartant opened this issue Nov 3, 2017 · 4 comments
Closed

Comments

@cartant
Copy link

cartant commented Nov 3, 2017

[REQUIRED] Describe your environment

  • Operating System version: N/A
  • Firebase SDK version: 4.6.1
  • Firebase Product: database

[REQUIRED] Describe the problem

The callback typings for on and off are not consistent and effect errors when using TypeScript 2.6 and strictFunctionTypes.

With the code in this issue (in the Relevant Code section), this error is effected:

TSError: ⨯ Unable to compile TypeScript
index.ts (4,24): Argument of type '(a: DataSnapshot | null, b?: string | undefined) => any' is not assignable to parameter of type '((a: DataSnapshot, b?: string | null | undefined) => any) | undefined'.
  Type '(a: DataSnapshot | null, b?: string | undefined) => any' is not assignable to type '(a: DataSnapshot, b?: string | null | undefined) => any'.
    Types of parameters 'b' and 'b' are incompatible.
      Type 'string | null | undefined' is not assignable to type 'string | undefined'.
        Type 'null' is not assignable to type 'string | undefined'. (2345)
    at getOutput (...\node_modules\ts-node\src\index.ts:307:15)
    at ...\node_modules\ts-node\src\index.ts:336:16
    at Object.compile (...\node_modules\ts-node\src\index.ts:498:11)
    at Module.m._compile (...\node_modules\ts-node\src\index.ts:392:43)
    at Module._extensions..js (module.js:635:10)
    at Object.require.extensions.(anonymous function) [as .ts] (...\node_modules\ts-node\src\index.ts:395:12)
    at Module.load (module.js:545:32)
    at tryModuleLoad (module.js:508:12)
    at Function.Module._load (module.js:500:3)
    at Function.Module.runMain (module.js:665:10)

The problem is that the on method returns a callback with a signature that differs from that of the callback the off method accepts.

In particular, it's the type of the optional b parameter. In the callback returned by on its type is b?: string, but in the callback accepted by off its type is b?: string | null.

Steps to reproduce:

Compile the code included below using TypeScript 2.6.1, with the strictFunctionTypes option enabled or with the strict option set to true.

Relevant Code:

import * as firebase from "firebase";
function bug(query: firebase.database.Query): void {
    const listener = query.on("value", (snapshot: firebase.database.DataSnapshot | null) => {});
    query.off("value", listener);
}
@verylongword
Copy link

Same problem, not yet fixed: Typescript 3.1.6, "firebase": "^5.9.4",

@rommelpe
Copy link

Sorry for the delay here. I tried to reproduce this using Typescript: 3.7.2 with the latest version of Firebase JS SDK (7.4.0) but can't seem to replicate it.

I would be happy to investigate further if you could provide a MCV example that I can run locally.

@cartant
Copy link
Author

cartant commented Nov 19, 2019

The steps to reproduce the problem were included in the initial PR description. I would be surprised if it were not reproducible using the versions that were specified. That it cannot be reproduced - more than two years later - with the current versions does not surprise me. If you have attempted to reproduce it with the latest versions and have been unable to do so, closing the issue would seem the appropriate course of action.

@rommelpe
Copy link

We really apologize for the inconvenience this may have caused you and weren't able to get back soon. It may seem to be addressed in the previous releases. I'll be closing this issue now as part of the issue cleanup effort.

If you're still interested in working on this case and want to continue the discussion, just leave a comment here and we are happy to re-open this. Thank you for understanding.

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

No branches or pull requests

5 participants