[go: nahoru, domu]

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

Typescript: Returned types from firebaseTestEnvironment.authenticatedContext(...).firestore() are incompatible with modular v9 client SDK Firestore types #5550

Closed
sceee opened this issue Sep 27, 2021 · 1 comment

Comments

@sceee
Copy link
sceee commented Sep 27, 2021

[REQUIRED] Describe your environment

  • Operating System version: Windows 10
  • Browser version: N/A
  • Firebase SDK version: 9.1.0
  • Firebase Product: firestore

[REQUIRED] Describe the problem

In addition to the already fixed #5500, when using the modular v9 client SDK, the "Firestore" type returned by firebaseTestEnvironment.authenticatedContext(...).firestore() from @firebase/rules-unit-testing v2.0.1 is incompatible with the modular client SDK type "Firestore".

Steps to reproduce:

Compile the relevant code below using

  • "@firebase/rules-unit-testing": "2.0.1",
  • "firebase": "9.1.0",

Relevant Code:

import { initializeTestEnvironment, RulesTestEnvironment } from '@firebase/rules-unit-testing'
import { Firestore as ClientFirestore } from 'firebase/firestore'

let db: ClientFirestore
let firebaseTestEnvironment: RulesTestEnvironment

const rulesContent = fs.readFileSync(path.resolve(__dirname, '../../../firestore.rules'), 'utf8')
firebaseTestEnvironment = await initializeTestEnvironment({
      projectId: 'anyproj',
      firestore: {
        rules: rulesContent,
      },
    })

// This line fails to compile with "Type 'Firestore' is missing the following properties from type 'Firestore': type, toJSONts(2739)"
db = firebaseTestEnvironment.authenticatedContext('testuid', {}).firestore()
@Feiyang1
Copy link
Member

This is working as intended. The testing SDK returns a compat version of Firestore for backward compatibility. It is not compatible with the modular Firestore type, but you can pass it to any function exported from the modular SDK where a modular Firestore is accepted, such as ref().

For typing db in the example, you should use the type exported from @firebase/firestore-types:

import { FirebaseFirestore as CompatFirestore } from `@firebase/firestore-types`;

let db: CompatFirestore;

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