Skip to content

Commit d642e31

Browse files
committed
Update Firestore and RTDB types
1 parent ca2a243 commit d642e31

File tree

2 files changed

+47
-30
lines changed

2 files changed

+47
-30
lines changed

packages/firebase/compat/index.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5819,7 +5819,7 @@ declare namespace firebase.database {
58195819
* returning true.
58205820
*/
58215821
forEach(
5822-
action: (a: firebase.database.IteratorDataSnapshot) => boolean | void
5822+
action: (a: firebase.database.IteratedDataSnapshot) => boolean | void
58235823
): boolean;
58245824
/**
58255825
* Gets the priority value of the data in this `DataSnapshot`.
@@ -5997,6 +5997,10 @@ declare namespace firebase.database {
59975997
*/
59985998
toJSON(): Object | null;
59995999
}
6000+
6001+
interface IteratedDataSnapshot extends DataSnapshot {
6002+
key: string; // key of the location of this snapshot.
6003+
}
60006004

60016005
/**
60026006
* The Firebase Database service interface.

packages/firestore-types/index.d.ts

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ export type LogLevel =
5050
export function setLogLevel(logLevel: LogLevel): void;
5151

5252
export interface FirestoreDataConverter<
53-
AppModelType,
54-
DbModelType extends DocumentData = DocumentData
55-
> {
53+
AppModelType,
54+
DbModelType extends DocumentData = DocumentData
55+
> {
5656
toFirestore(modelObject: AppModelType): DocumentData;
5757
toFirestore(modelObject: Partial<AppModelType>, options: SetOptions): DocumentData;
5858

@@ -188,45 +188,53 @@ export class Blob {
188188
export class Transaction {
189189
private constructor();
190190

191-
get<T>(documentRef: DocumentReference<AppModelType, DbModelType>): Promise<DocumentSnapshot<AppModelType, DbModelType>>;
191+
get<AppModelType, DbModelType extends DocumentData>(
192+
documentRef: DocumentReference<AppModelType, DbModelType>
193+
): Promise<DocumentSnapshot<AppModelType, DbModelType>>;
192194

193-
set<T>(
195+
set<AppModelType, DbModelType extends DocumentData>(
194196
documentRef: DocumentReference<AppModelType, DbModelType>,
195-
data: Partial<T>,
197+
data: Partial<AppModelType>,
196198
options: SetOptions
197199
): Transaction;
198-
set<T>(documentRef: DocumentReference<AppModelType, DbModelType>, data: T): Transaction;
200+
set<AppModelType, DbModelType extends DocumentData>(
201+
documentRef: DocumentReference<AppModelType, DbModelType>,
202+
data: Partial<AppModelType>
203+
): Transaction;
199204

200-
update(documentRef: DocumentReference<any>, data: UpdateData): Transaction;
201-
update(
202-
documentRef: DocumentReference<any>,
205+
update<AppModelType, DbModelType extends DocumentData>(
206+
documentRef: DocumentReference<AppModelType, DbModelType>,
207+
data: Partial<AppModelType>
208+
): Transaction;
209+
update<AppModelType, DbModelType extends DocumentData>(
210+
documentRef: DocumentReference<AppModelType, DbModelType>,
203211
field: string | FieldPath,
204212
value: any,
205213
...moreFieldsAndValues: any[]
206214
): Transaction;
207215

208-
delete(documentRef: DocumentReference<any>): Transaction;
216+
delete<AppModelType, DbModelType extends DocumentData>(documentRef: DocumentReference<AppModelType, DbModelType>): Transaction;
209217
}
210218

211219
export class WriteBatch {
212220
private constructor();
213221

214-
set<T>(
222+
set<AppModelType, DbModelType extends DocumentData>(
215223
documentRef: DocumentReference<AppModelType, DbModelType>,
216-
data: Partial<T>,
224+
data: Partial<AppModelType>,
217225
options: SetOptions
218226
): WriteBatch;
219-
set<T>(documentRef: DocumentReference<AppModelType, DbModelType>, data: T): WriteBatch;
227+
set<AppModelType, DbModelType extends DocumentData>(documentRef: DocumentReference<AppModelType, DbModelType>, data: UpdateData): WriteBatch;
220228

221-
update(documentRef: DocumentReference<any>, data: UpdateData): WriteBatch;
222-
update(
223-
documentRef: DocumentReference<any>,
229+
update<AppModelType, DbModelType extends DocumentData>(documentRef: DocumentReference<AppModelType, DbModelType>, data: UpdateData): WriteBatch;
230+
update<AppModelType, DbModelType extends DocumentData>(
231+
documentRef: DocumentReference<AppModelType, DbModelType>,
224232
field: string | FieldPath,
225233
value: any,
226234
...moreFieldsAndValues: any[]
227235
): WriteBatch;
228236

229-
delete(documentRef: DocumentReference<any>): WriteBatch;
237+
delete<AppModelType, DbModelType extends DocumentData>(documentRef: DocumentReference<AppModelType, DbModelType>): WriteBatch;
230238

231239
commit(): Promise<void>;
232240
}
@@ -256,8 +264,8 @@ export class DocumentReference<AppModelType, DbModelType> {
256264

257265
isEqual(other: DocumentReference<AppModelType, DbModelType>): boolean;
258266

259-
set(data: Partial<T>, options: SetOptions): Promise<void>;
260-
set(data: T): Promise<void>;
267+
set(data: Partial<AppModelType>, options: SetOptions): Promise<void>;
268+
set(data: Partial<AppModelType>): Promise<void>;
261269

262270
update(data: UpdateData): Promise<void>;
263271
update(
@@ -295,8 +303,10 @@ export class DocumentReference<AppModelType, DbModelType> {
295303
onCompletion?: () => void
296304
): () => void;
297305

298-
withConverter(converter: null): DocumentReference<DocumentData>;
299-
withConverter<U>(converter: FirestoreDataConverter<U>): DocumentReference<U>;
306+
withConverter(converter: null): DocumentReference<AppModelType, DbModelType>;
307+
withConverter<AppModelType, DbModelType>(
308+
converter: FirestoreDataConverter<AppModelType, DbModelType>
309+
): DocumentReference<AppModelType, DbModelType>;
300310
}
301311

302312
export interface SnapshotOptions {
@@ -318,7 +328,7 @@ export class DocumentSnapshot<AppModelType, DbModelType> {
318328
readonly id: string;
319329
readonly metadata: SnapshotMetadata;
320330

321-
data(options?: SnapshotOptions): T | undefined;
331+
data(options?: SnapshotOptions): AppModelType | undefined;
322332

323333
get(fieldPath: string | FieldPath, options?: SnapshotOptions): any;
324334

@@ -329,7 +339,7 @@ export class QueryDocumentSnapshot<AppModelType, DbModelType>
329339
extends DocumentSnapshot<AppModelType, DbModelType> {
330340
private constructor();
331341

332-
data(options?: SnapshotOptions): T;
342+
data(options?: SnapshotOptions): AppModelType;
333343
}
334344

335345
export type OrderByDirection = 'desc' | 'asc';
@@ -420,7 +430,7 @@ export class QuerySnapshot<AppModelType, DbModelType> {
420430
readonly size: number;
421431
readonly empty: boolean;
422432

423-
docChanges(options?: SnapshotListenOptions): Array<DocumentChange<T>>;
433+
docChanges(options?: SnapshotListenOptions): Array<DocumentChange<AppModelType, DbModelType>>;
424434

425435
forEach(
426436
callback: (result: QueryDocumentSnapshot<AppModelType, DbModelType>) => void,
@@ -439,18 +449,21 @@ export interface DocumentChange<AppModelType, DbModelType> {
439449
readonly newIndex: number;
440450
}
441451

442-
export class CollectionReference<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData> extends Query<AppModelType, DbModelType> {
452+
export class CollectionReference<
453+
AppModelType = DocumentData,
454+
DbModelType extends DocumentData = DocumentData
455+
> extends Query<AppModelType, DbModelType> {
443456
private constructor();
444457

445458
readonly id: string;
446-
readonly parent: DocumentReference<AppModelType, DbModelType>| null;
459+
readonly parent: DocumentReference<AppModelType, DbModelType> | null;
447460
readonly path: string;
448461

449462
doc(documentPath?: string): DocumentReference<AppModelType, DbModelType>;
450463

451-
add(data: T): Promise<DocumentReference<AppModelType, DbModelType>>;
464+
add(data: AppModelType): Promise<DocumentReference<AppModelType, DbModelType>>;
452465

453-
isEqual(other: CollectionReference<T>): boolean;
466+
isEqual(other: CollectionReference<AppModelType, DbModelType>): boolean;
454467

455468
withConverter(converter: null): CollectionReference<DocumentData>;
456469
withConverter<U>(

0 commit comments

Comments
 (0)