Skip to content

Commit f59de3b

Browse files
committed
fix: address review on ReactFireOptions type tightening
- Cast initialData in getServerSnapshot (#779) now that it is no longer `any`. - Move the type test to test/ so it stays out of dist/ and the tarball; drop .npmignore. - Cover useFirestoreDocOnce in the type test.
1 parent d31060a commit f59de3b

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

‎.npmignore‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎src/useObservable.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export function useObservable<T = unknown>(observableId: string, source: Observa
122122
status: hasInitialData ? 'success' : 'loading',
123123
hasEmitted: hasInitialData,
124124
isComplete: false,
125-
data: initialDataValue,
125+
data: initialDataValue as T,
126126
error: undefined,
127127
firstValuePromise: observable.firstEmission
128128
};
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
22
* Type-level regression tests for ReactFireOptions<T> generic constraints.
3-
* Checked by `tsc --noEmit` in CI. No runtime behavior — not bundled.
3+
* Checked by `tsc --noEmit -p tsconfig.test.json` in CI. No runtime behavior.
44
*/
5-
import type { ReactFireOptions } from './index';
5+
import type { ReactFireOptions } from '../src/index';
66

77
// ---- initialData must match T ----
88

@@ -25,22 +25,27 @@ void _wrongStartWithValue;
2525
// only value you can actually have) stops compiling.
2626

2727
import type { DocumentReference, DocumentSnapshot, Query, QuerySnapshot } from 'firebase/firestore';
28-
import type { useFirestoreCollection, useFirestoreDoc, useFirestoreDocData } from './firestore';
28+
import type { useFirestoreCollection, useFirestoreDoc, useFirestoreDocData, useFirestoreDocOnce } from '../src/firestore';
2929

3030
declare const ref: DocumentReference<{ a: string }>;
3131
declare const query: Query<{ a: string }>;
3232
declare const snap: DocumentSnapshot<{ a: string }>;
3333
declare const querySnap: QuerySnapshot<{ a: string }>;
3434
declare const docHook: typeof useFirestoreDoc;
35+
declare const docOnceHook: typeof useFirestoreDocOnce;
3536
declare const collectionHook: typeof useFirestoreCollection;
3637
declare const dataHook: typeof useFirestoreDocData;
3738

3839
void (() => docHook(ref, { initialData: snap }));
40+
void (() => docOnceHook(ref, { initialData: snap }));
3941
void (() => collectionHook(query, { initialData: querySnap }));
4042
void (() => dataHook(ref, { initialData: { a: 'x' } }));
4143

4244
// @ts-expect-error a snapshot hook must not accept the unwrapped data type
4345
void (() => docHook(ref, { initialData: { a: 'x' } }));
4446

47+
// @ts-expect-error a snapshot hook must not accept the unwrapped data type
48+
void (() => docOnceHook(ref, { initialData: { a: 'x' } }));
49+
4550
// @ts-expect-error a data hook must not accept a snapshot
4651
void (() => dataHook(ref, { initialData: snap }));

0 commit comments

Comments
 (0)