angularfire
angularfire copied to clipboard
There's something wrong with release 7.6.1
Version info
Angular: 16.1.3
Firebase: 9.23.0
AngularFire: 7.6.1
How to reproduce these conditions
Steps to set up and reproduce
Just download the .zip with the code of version 7.6.1 and open the file `src/compat/firestore/interfaces.ts.
You'll see that the released code in this file doesn't correspond with what's actually in the master
branch.
From the release:
import { Subscriber } from 'rxjs';
import firebase from 'firebase/compat/app';
export type Settings = firebase.firestore.Settings;
export type CollectionReference<T = DocumentData> = firebase.firestore.CollectionReference<T>;
export type DocumentReference<T = DocumentData> = firebase.firestore.DocumentReference<T>;
export type PersistenceSettings = firebase.firestore.PersistenceSettings;
export type DocumentChangeType = firebase.firestore.DocumentChangeType;
export type SnapshotOptions = firebase.firestore.SnapshotOptions;
export type FieldPath = firebase.firestore.FieldPath;
export type Query<T = DocumentData> = firebase.firestore.Query<T>;
export type SetOptions = firebase.firestore.SetOptions;
export type DocumentData = firebase.firestore.DocumentData;
export interface DocumentSnapshotExists<T> extends firebase.firestore.DocumentSnapshot {
readonly exists: true;
data(options?: SnapshotOptions): T;
}
export interface DocumentSnapshotDoesNotExist extends firebase.firestore.DocumentSnapshot {
readonly exists: false;
data(options?: SnapshotOptions): undefined;
get(fieldPath: string | FieldPath, options?: SnapshotOptions): undefined;
}
export type DocumentSnapshot<T> = DocumentSnapshotExists<T> | DocumentSnapshotDoesNotExist;
export interface QueryDocumentSnapshot<T> extends firebase.firestore.QueryDocumentSnapshot {
data(options?: SnapshotOptions): T;
}
export interface QuerySnapshot<T> extends firebase.firestore.QuerySnapshot {
readonly docs: QueryDocumentSnapshot<T>[];
}
export interface DocumentChange<T> extends firebase.firestore.DocumentChange {
readonly doc: QueryDocumentSnapshot<T>;
}
You can see that the interfaces DocumentSnapshotExists
, QueryDocumentSnapshot
, QuerySnapshot
, and DocumentChange
are incorrectly extending the interfaces from firebase.firestore
.
However, that's not the code that can be seen in the master
branch:
https://github.com/angular/angularfire/blob/34e89a4625646ff446f2a49c8d8bc489fc917655/src/compat/firestore/interfaces.ts#L1-L40
NOTE: I have cloned the repo and run a yarn build
to see the result, and I've confirmed that that command is generating the right code. I don't know what is on the 7.6.1 release, but it's not the direct result from cloning master
and running a yarn build
command.
Debug output
Errors in the console
I get the following errors while trying to compile the project:
node_modules/@angular/fire/compat/firestore/interfaces.d.ts:13:41
13 export interface DocumentSnapshotExists<T> extends firebase.firestore.DocumentSnapshot {
~
This type parameter might need an `extends firebase.firestore.DocumentData` constraint.
node_modules/@angular/fire/compat/firestore/interfaces.d.ts:13:41
13 export interface DocumentSnapshotExists<T> extends firebase.firestore.DocumentSnapshot {
~
This type parameter might need an `extends firebase.firestore.DocumentData | undefined` constraint.
Error: node_modules/@angular/fire/compat/firestore/interfaces.d.ts:23:18 - error TS2430: Interface 'QueryDocumentSnapshot<T>' incorrectly extends interface 'QueryDocumentSnapshot<DocumentData>'.
The types returned by 'data(...)' are incompatible between these types.
Type 'T' is not assignable to type 'DocumentData'.
23 export interface QueryDocumentSnapshot<T> extends firebase.firestore.QueryDocumentSnapshot {
~~~~~~~~~~~~~~~~~~~~~
node_modules/@angular/fire/compat/firestore/interfaces.d.ts:23:40
23 export interface QueryDocumentSnapshot<T> extends firebase.firestore.QueryDocumentSnapshot {
~
This type parameter might need an `extends firebase.firestore.DocumentData` constraint.
Error: node_modules/@angular/fire/compat/firestore/interfaces.d.ts:26:18 - error TS2430: Interface 'QuerySnapshot<T>' incorrectly extends interface 'QuerySnapshot<DocumentData>'.
Types of property 'docs' are incompatible.
Type 'QueryDocumentSnapshot<T>[]' is not assignable to type 'QueryDocumentSnapshot<DocumentData>[]'.
Type 'QueryDocumentSnapshot<T>' is not assignable to type 'QueryDocumentSnapshot<DocumentData>'.
The types returned by 'data(...)' are incompatible between these types.
Type 'T' is not assignable to type 'DocumentData'.
26 export interface QuerySnapshot<T> extends firebase.firestore.QuerySnapshot {
~~~~~~~~~~~~~
node_modules/@angular/fire/compat/firestore/interfaces.d.ts:26:32
26 export interface QuerySnapshot<T> extends firebase.firestore.QuerySnapshot {
~
This type parameter might need an `extends firebase.firestore.DocumentData` constraint.
Error: node_modules/@angular/fire/compat/firestore/interfaces.d.ts:29:18 - error TS2430: Interface 'DocumentChange<T>' incorrectly extends interface 'DocumentChange<DocumentData>'.
The types returned by 'doc.data(...)' are incompatible between these types.
Type 'T' is not assignable to type 'DocumentData'.
29 export interface DocumentChange<T> extends firebase.firestore.DocumentChange {
~~~~~~~~~~~~~~
node_modules/@angular/fire/compat/firestore/interfaces.d.ts:29:33
29 export interface DocumentChange<T> extends firebase.firestore.DocumentChange {
~
This type parameter might need an `extends firebase.firestore.DocumentData` constraint.
Expected behavior
The project should compile.
Actual behavior
The project doesn't compile.
https://github.com/angular/angularfire/issues/3290#issuecomment-1323837275
Yeah, @beppo-ivel, it's related to that issue. I mean, the fix is in the code, the only thing necessary now is for the release to reflect that code...
y donde está la solución ?
@andres24h I guess they have to build and release a new version, but this time including the actual code? I don't know where the problem is exactly...
Hi,
Somebody can know when will be populate the next release which contains this fixes?
same here, any solution?
If you switch from the compat to modular then the types are correct for that version.
For example:
import { Injectable } from '@angular/core';
// eslint-disable-next-line @typescript-eslint/consistent-type-imports -- Functions is Angular Injected
import { Functions, httpsCallableData } from '@angular/fire/functions';
import type { HttpsCallableOptions } from '@angular/fire/functions';
import type { Observable } from 'rxjs';
type HttpsCallableDataFunction<RequestData, ResponseData> = (data: RequestData) => Observable<ResponseData>;
export type { HttpsCallableDataFunction };
@Injectable({ providedIn: 'root' })
export class AngularFireFunctionsService {
constructor(private readonly func: Functions) {}
public httpsCallable<RequestData = unknown, ResponseData = unknown>(
name: string,
options?: HttpsCallableOptions,
): HttpsCallableDataFunction<RequestData, ResponseData> {
return httpsCallableData<RequestData, ResponseData>(this.func, name, options);
}
}
I wrap the modular methods in an Angular Service for easier mocking when unit testing.