Skip to content

Commit 18d43c9

Browse files
committed
fix: tighten ReactFireOptions generic types, remove T | any widening
Removes `| any` from `initialData` and `startWithValue`, so a value of the wrong type is a TypeScript error rather than silently accepted. `T | any` collapses to `any`, so the generic never enforced anything. Tightens `checkIdField` to read `options?.idField` directly, and narrows `checkOptions` / `checkinitialData` from `any` to `unknown`. Both are kept as exports; removal is tracked in #754. Adds casts at the rxfire `docData` / `collectionData` call sites, where rxfire expects `keyof T` and the field is a plain string. Adds `src/reactfire-options.type-test.ts`, five `@ts-expect-error` assertions riding the existing `tsc --noEmit` CI, kept out of the tarball by `.npmignore`. The negative-case consts are consumed so the directives are load-bearing: without that, `noUnusedLocals` satisfies them with a TS6133 and the file passes even if the tightening is reverted. Breaking for the raw snapshot hooks: their correct `initialData` is a `DocumentSnapshot<T>` / `QuerySnapshot<T>`, and the interface now says `T`, so correct usage stops compiling. #741 tracks the real fix and is required for 5.0.0. Fixes #383.
1 parent 0b70a12 commit 18d43c9

12 files changed

Lines changed: 47 additions & 25 deletions

‎.npmignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src/*.type-test.ts

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Firebase.
1313

1414
## Platform support
1515

16-
ReactFire is designed for **web React apps** and wraps the [Firebase Web SDK](https://firebase.google.com/docs/web/setup). It is not compatible with React Native or Expo. For React Native projects, use [react-native-firebase](https://rnfirebase.io/) instead.
16+
ReactFire is designed for **web React apps** and wraps the [Firebase JavaScript SDK](https://firebase.google.com/docs/web/setup). It is not compatible with React Native or Expo. For React Native projects, use [react-native-firebase](https://rnfirebase.io/) instead.
1717

1818
## Install
1919

‎docs/reference/functions/checkIdField.md‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/reference/functions/checkOptions.md‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/reference/functions/checkinitialData.md‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/reference/interfaces/ReactFireOptions.md‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/reference/interfaces/SignInCheckOptionsBasic.md‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/reference/interfaces/SignInCheckOptionsClaimsObject.md‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/reference/interfaces/SignInCheckOptionsClaimsValidator.md‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/firestore.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export function useFirestoreDocData<T = unknown>(ref: DocumentReference<T>, opti
6363
const idField = options ? checkIdField(options) : undefined;
6464

6565
const observableId = `firestore:docData:${ref.firestore.app.name}:${ref.path}:idField=${JSON.stringify(idField)}`;
66-
const observable = docData(ref, { idField });
66+
const observable = docData(ref, { idField: idField as keyof T });
6767

6868
return useObservable(observableId, observable, options) as ObservableStatus<T>;
6969
}
@@ -75,7 +75,7 @@ export function useFirestoreDocDataOnce<T = unknown>(ref: DocumentReference<T>,
7575
const idField = options ? checkIdField(options) : undefined;
7676

7777
const observableId = `firestore:docDataOnce:${ref.firestore.app.name}:${ref.path}:idField=${JSON.stringify(idField)}`;
78-
const observable$ = docData(ref, { idField }).pipe(first());
78+
const observable$ = docData(ref, { idField: idField as keyof T }).pipe(first());
7979

8080
return useObservable(observableId, observable$, options) as ObservableStatus<T>;
8181
}
@@ -96,7 +96,7 @@ export function useFirestoreCollection<T = DocumentData>(query: FirestoreQuery<T
9696
export function useFirestoreCollectionData<T = DocumentData>(query: FirestoreQuery<T>, options?: ReactFireOptions<T[]>): ObservableStatus<T[]> {
9797
const idField = options ? checkIdField(options) : undefined;
9898
const observableId = `firestore:collectionData:${getUniqueIdForFirestoreQuery(query)}:idField=${JSON.stringify(idField)}`;
99-
const observable$ = collectionData(query, { idField });
99+
const observable$ = collectionData(query, { idField: idField as (string & keyof T) });
100100

101101
return useObservable(observableId, observable$, options);
102102
}

0 commit comments

Comments
 (0)