Skip to content

firestore QueryDocumentSnapshot type mismatch between compat & new lib #6081

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
goleary opened this issue Mar 18, 2022 · 3 comments
Closed

Comments

@goleary
Copy link

goleary commented Mar 18, 2022

[REQUIRED] Describe your environment

  • Operating System version: window 11
  • Browser version: n/a
  • Firebase SDK version: 9.6.9
  • Firebase Product: firestore

[REQUIRED] Describe the problem

There is a type mismatch between the QueryDocumentSnapshot exported by firebase/firestore & firebase/compat/app.

We've are hoping to incrementally adopt the modular style/syntax of version 9 of this library.

We have converters that are defined using the types exported from firebase/firestore, but we use these converters with code exported from firebase/compat/app/firebase/compat/firestore.

i.e.

import firebase from 'firebase/compat/app';
import 'firebase/compat/firestore';

import ThingyConverter from './converter'; // defined using type from new module

...
const docRef = firebase.firestore().doc('col/1).withConverter(ThingConverter)

Attempting to do so result in a type error.

Type 'firebase.default.firestore.QueryDocumentSnapshot<firebase.default.firestore.DocumentData>' is not assignable to type 'import(".../firebase-converter-type-repro/node_modules/@firebase/firestore/dist/index").QueryDocumentSnapshot<import(".../firebase-converter-type-repro/node_modules/@firebase/firestore/dist/index").DocumentData>'.
  Types of property 'exists' are incompatible.
    Type 'boolean' is not assignable to type '() => this is QueryDocumentSnapshot<DocumentData>'.ts(2322)

I don't understand why these types don't match, they are exported from the same package.

Relevant Code:

This is a minimal repro that exhibits the type error
https://github.com/goleary/firebase-converter-type-repro

@google-oss-bot
Copy link
Contributor

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@schmidt-sebastian
Copy link
Contributor

The types exposed by firestore-compat and firestore are not interchangeable. QueryDocumentSnapshot.exists() is a a function in v9, as we would to use the return type as a type-guard. While you should be able to use the QueryDocumentSnapshot from firestore-compat and firestore in all of our Firestore APIs, you cannot assign them to the same variable as TS will correctly detect the signature mismatch.

Let us know if you need more information.

@schmidt-sebastian schmidt-sebastian self-assigned this Mar 18, 2022
@schmidt-sebastian schmidt-sebastian removed their assignment Apr 14, 2022
@jbalidiong
Copy link
Contributor

I'll be closing this for now. If the issue persists, feel free to comment and reopen this issue.

@firebase firebase locked and limited conversation to collaborators May 27, 2022
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

4 participants