firebase-js-sdk icon indicating copy to clipboard operation
firebase-js-sdk copied to clipboard

Incompatible DataSnapshot types with AngularFire

Open JosehGaks opened this issue 3 years ago • 2 comments

Environment

  • Operating System version: Windows 10 pro version 21H1
  • Browser version: Mozilla firefox 21H1
  • Firebase SDK version: 9.9.2
  • Firebase Product: database (auth, database, storage, etc)

I was trying to serve an Angular CLI: 13.3.6 application

Steps to reproduce:

Relevant Code:

`Error: node_modules/@angular/fire/compat/database/interfaces.d.ts:47:18 - error TS2430: Interface 'DatabaseSnapshotExists<T>' incorrectly extends interface 'DataSnapshot'. Types of property 'forEach' are incompatible. Type '(action: (a: DatabaseSnapshot<T>) => boolean) => boolean' is not assignable to type '(action: (a: DataSnapshot & { key: string; }) => boolean | void) => boolean'. Types of parameters 'action' and 'action' are incompatible. Types of parameters 'a' and 'a' are incompatible. Type 'DatabaseSnapshot<T>' is not assignable to type 'DataSnapshot & { key: string; }'. Type 'DatabaseSnapshotExists<T>' is not assignable to type 'DataSnapshot & { key: string; }'.
Type 'DatabaseSnapshotExists<T>' is not assignable to type 'DataSnapshot'. Types of property 'forEach' are incompatible. Type '(action: (a: DatabaseSnapshot<T>) => boolean) => boolean' is not assignable to type '(action: (a: DataSnapshot & { key: string; }) => boolean | void) => boolean'. Types of parameters 'action' and 'action' are incompatible. Types of parameters 'a' and 'a' are incompatible. Type 'DatabaseSnapshot<T>' is not assignable to type 'DataSnapshot & { key: string; }'. Type 'DatabaseSnapshotDoesNotExist<T>' is not assignable to type 'DataSnapshot & { key: string; }'. Type 'DatabaseSnapshotDoesNotExist<T>' is not assignable to type '{ key: string; }'. Types of property 'key' are incompatible. Type 'string | null' is not assignable to type 'string'. Type 'null' is not assignable to type 'string'.

47 export interface DatabaseSnapshotExists<T> extends firebase.database.DataSnapshot { m ~~~~~~~~~~~~~~~~~~~~~~

Error: node_modules/@angular/fire/compat/database/interfaces.d.ts:52:18 - error TS2430: Interface 'DatabaseSnapshotDoesNotExist<T>' incorrectly extends interface 'DataSnapshot'. Types of property 'forEach' are incompatible. Type '(action: (a: DatabaseSnapshot<T>) => boolean) => boolean' is not assignable to type '(action: (a: DataSnapshot & { key: string; }) => boolean | void) => boolean'. Types of parameters 'action' and 'action' are incompatible. Types of parameters 'a' and 'a' are incompatible. Type 'DatabaseSnapshot<T>' is not assignable to type 'DataSnapshot & { key: string; }'. Type 'DatabaseSnapshotDoesNotExist<T>' is not assignable to type 'DataSnapshot & { key: string; }'. Type 'DatabaseSnapshotDoesNotExist<T>' is not assignable to type 'DataSnapshot'. Types of property 'forEach' are incompatible. Type '(action: (a: DatabaseSnapshot<T>) => boolean) => boolean' is not assignable to type '(action: (a: DataSnapshot & { key: string; }) => boolean | void) => boolean'. Types of parameters 'action' and 'action' are incompatible. Types of parameters 'a' and 'a' are incompatible. Type 'DatabaseSnapshot<T>' is not assignable to type 'DataSnapshot & { key: string; }'. Type 'DatabaseSnapshotExists<T>' is not assignable to type 'DataSnapshot & { key: string; }'. Type 'DatabaseSnapshotExists<T>' is not assignable to type '{ key: string; }'.
Types of property 'key' are incompatible. Type 'string | null' is not assignable to type 'string'. Type 'null' is not assignable to type 'string'.

52 export interface DatabaseSnapshotDoesNotExist<T> extends firebase.database.DataSnapshot { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

× Failed to compile.`

```

JosehGaks avatar Aug 07 '22 10:08 JosehGaks

@JosehGaks this was caused by the release of 9.9.2. Can you please try 9.9.1 in the meantime?

maneesht avatar Aug 07 '22 22:08 maneesht

@JosehGaks - can you also provide the exact code that gave you this error?

maneesht avatar Aug 07 '22 22:08 maneesht

export interface **DatabaseSnapshotExists**<T> extends firebase.database.DataSnapshot {
    exists(): true;
    val(): T;
    forEach(action: (a: DatabaseSnapshot<T>) => boolean): boolean;
}
export interface **DatabaseSnapshotDoesNotExist**<T> extends firebase.database.DataSnapshot {
    exists(): false;
    val(): null;
    forEach(action: (a: DatabaseSnapshot<T>) => boolean): boolean;
}

ImeedAttia avatar Aug 12 '22 15:08 ImeedAttia

Thanks.I used an older version and it worked great.

JosehGaks avatar Aug 12 '22 15:08 JosehGaks

@ImeedAttia thank you. I meant can you provide the code in your application that caused this error?

maneesht avatar Aug 12 '22 16:08 maneesht

This should be fixed in the latest release.

maneesht avatar Aug 18 '22 22:08 maneesht