Skip to content

Commit 6295a5c

Browse files
committed
fix: add ListenerSource type instead of literal union
1 parent afa4465 commit 6295a5c

4 files changed

Lines changed: 9 additions & 7 deletions

File tree

packages/firestore/lib/FirestoreDocumentReference.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import type DocumentSnapshot from './FirestoreDocumentSnapshot';
3838
import type { FirestoreInternal, FirestoreSyncEventBodyInternal } from './types/internal';
3939
import type { DocumentSnapshotNativeData } from './FirestoreDocumentSnapshot';
4040
import type FirestorePath from './FirestorePath';
41-
import type { DocumentData, FirestoreDataConverter } from './types/firestore';
41+
import type { DocumentData, FirestoreDataConverter, ListenSource } from './types/firestore';
4242

4343
let FirestoreCollectionReference:
4444
| (new (
@@ -188,7 +188,7 @@ export default class DocumentReference {
188188
}
189189

190190
onSnapshot(...args: unknown[]): () => void {
191-
let snapshotListenOptions: { includeMetadataChanges?: boolean; source?: 'default' | 'cache' };
191+
let snapshotListenOptions: { includeMetadataChanges?: boolean; source?: ListenSource };
192192
let callback: (snapshot: DocumentSnapshot | null, error: Error | null) => void;
193193
let onNext: (snapshot: DocumentSnapshot) => void;
194194
let onError: (error: Error) => void;

packages/firestore/lib/FirestoreQuery.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import QuerySnapshot, { type QuerySnapshotNativeData } from './FirestoreQuerySna
3434
import { parseSnapshotArgs, validateWithConverter } from './utils';
3535

3636
import type FirestorePath from './FirestorePath';
37-
import type { DocumentData, FirestoreDataConverter } from './types/firestore';
37+
import type { DocumentData, FirestoreDataConverter, ListenSource } from './types/firestore';
3838
import type {
3939
FirestoreInternal,
4040
DocumentFieldValueInternal,
@@ -331,7 +331,7 @@ export default class Query {
331331
}
332332

333333
onSnapshot(...args: unknown[]): () => void {
334-
let snapshotListenOptions: { includeMetadataChanges?: boolean; source?: 'default' | 'cache' };
334+
let snapshotListenOptions: { includeMetadataChanges?: boolean; source?: ListenSource };
335335
let callback: (snapshot: QuerySnapshot | null, error: Error | null) => void;
336336
let onNext: (snapshot: QuerySnapshot) => void;
337337
let onError: (error: Error) => void;

packages/firestore/lib/types/namespaced.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
import { ReactNativeFirebase } from '@react-native-firebase/app';
19+
import type { ListenSource } from './firestore';
1920

2021
/**
2122
* Firebase Cloud Firestore package for React Native.
@@ -1768,7 +1769,7 @@ export namespace FirebaseFirestoreTypes {
17681769
/**
17691770
* Set the source the query listens to. Default is 'default'.
17701771
*/
1771-
source?: 'default' | 'cache';
1772+
source?: ListenSource;
17721773
}
17731774

17741775
/**

packages/firestore/lib/utils/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import type {
3131
PartialSnapshotObserverInternal,
3232
} from '../types/internal';
3333
import FieldPath, { fromDotSeparatedString } from '../FieldPath';
34+
import type { ListenSource } from 'lib/types/firestore';
3435

3536
export function extractFieldPathData(data: unknown, segments: string[]): unknown {
3637
if (!isObject(data)) {
@@ -153,7 +154,7 @@ function isPartialObserver(
153154
export interface ParseSnapshotArgsResult {
154155
snapshotListenOptions: {
155156
includeMetadataChanges?: boolean;
156-
source?: 'default' | 'cache';
157+
source?: ListenSource;
157158
};
158159
callback: (snapshot: unknown, error: Error | null) => void;
159160
onNext: (snapshot: unknown) => void;
@@ -168,7 +169,7 @@ export function parseSnapshotArgs(args: unknown[]): ParseSnapshotArgsResult {
168169
const NOOP = (): void => {};
169170
const snapshotListenOptions: {
170171
includeMetadataChanges?: boolean;
171-
source?: 'default' | 'cache';
172+
source?: ListenSource;
172173
} = {};
173174
let callback: (snapshot: unknown, error: Error | null) => void = NOOP;
174175
let onError: (error: Error) => void = NOOP;

0 commit comments

Comments
 (0)