Skip to content

Commit fe1ef62

Browse files
Merge master into release
2 parents 2e6f600 + 47860fe commit fe1ef62

File tree

7 files changed

+79
-13
lines changed

7 files changed

+79
-13
lines changed

.changeset/empty-boats-dream.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@firebase/firestore-types': major
3+
'firebase': major
4+
---
5+
6+
Update to be consistent with the FirestoreDataConverter changes from #7310

.changeset/soft-grapes-occur.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'firebase': patch
3+
---
4+
5+
Fix typings for v10

docs-devsite/database.datasnapshot.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export declare class DataSnapshot
3838
| [child(path)](./database.datasnapshot.md#datasnapshotchild) | | Gets another <code>DataSnapshot</code> for the location at the specified relative path.<!-- -->Passing a relative path to the <code>child()</code> method of a DataSnapshot returns another <code>DataSnapshot</code> for the location at the specified relative path. The relative path can either be a simple child name (for example, "ada") or a deeper, slash-separated path (for example, "ada/name/first"). If the child location has no data, an empty <code>DataSnapshot</code> (that is, a <code>DataSnapshot</code> whose value is <code>null</code>) is returned. |
3939
| [exists()](./database.datasnapshot.md#datasnapshotexists) | | Returns true if this <code>DataSnapshot</code> contains any data. It is slightly more efficient than using <code>snapshot.val() !== null</code>. |
4040
| [exportVal()](./database.datasnapshot.md#datasnapshotexportval) | | Exports the entire contents of the DataSnapshot as a JavaScript object.<!-- -->The <code>exportVal()</code> method is similar to <code>val()</code>, except priority information is included (if available), making it suitable for backing up your data. |
41-
| [forEach(action)](./database.datasnapshot.md#datasnapshotforeach) | | Enumerates the top-level children in the <code>DataSnapshot</code>.<!-- -->Because of the way JavaScript objects work, the ordering of data in the JavaScript object returned by <code>val()</code> is not guaranteed to match the ordering on the server nor the ordering of <code>onChildAdded()</code> events. That is where <code>forEach()</code> comes in handy. It guarantees the children of a <code>DataSnapshot</code> will be iterated in their query order.<!-- -->If no explicit <code>orderBy*()</code> method is used, results are returned ordered by key (unless priorities are used, in which case, results are returned by priority). |
41+
| [forEach(action)](./database.datasnapshot.md#datasnapshotforeach) | | Enumerates the top-level children in the <code>IteratedDataSnapshot</code>.<!-- -->Because of the way JavaScript objects work, the ordering of data in the JavaScript object returned by <code>val()</code> is not guaranteed to match the ordering on the server nor the ordering of <code>onChildAdded()</code> events. That is where <code>forEach()</code> comes in handy. It guarantees the children of a <code>DataSnapshot</code> will be iterated in their query order.<!-- -->If no explicit <code>orderBy*()</code> method is used, results are returned ordered by key (unless priorities are used, in which case, results are returned by priority). |
4242
| [hasChild(path)](./database.datasnapshot.md#datasnapshothaschild) | | Returns true if the specified child path has (non-null) data. |
4343
| [hasChildren()](./database.datasnapshot.md#datasnapshothaschildren) | | Returns whether or not the <code>DataSnapshot</code> has any non-<code>null</code> child properties.<!-- -->You can use <code>hasChildren()</code> to determine if a <code>DataSnapshot</code> has any children. If it does, you can enumerate them using <code>forEach()</code>. If it doesn't, then either this snapshot contains a primitive value (which can be retrieved with <code>val()</code>) or it is empty (in which case, <code>val()</code> will return <code>null</code>). |
4444
| [toJSON()](./database.datasnapshot.md#datasnapshottojson) | | Returns a JSON-serializable representation of this object. |
@@ -142,7 +142,7 @@ The DataSnapshot's contents as a JavaScript value (Object, Array, string, number
142142

143143
## DataSnapshot.forEach()
144144

145-
Enumerates the top-level children in the `DataSnapshot`<!-- -->.
145+
Enumerates the top-level children in the `IteratedDataSnapshot`<!-- -->.
146146

147147
Because of the way JavaScript objects work, the ordering of data in the JavaScript object returned by `val()` is not guaranteed to match the ordering on the server nor the ordering of `onChildAdded()` events. That is where `forEach()` comes in handy. It guarantees the children of a `DataSnapshot` will be iterated in their query order.
148148

@@ -151,14 +151,14 @@ If no explicit `orderBy*()` method is used, results are returned ordered by key
151151
<b>Signature:</b>
152152

153153
```typescript
154-
forEach(action: (child: DataSnapshot) => boolean | void): boolean;
154+
forEach(action: (child: IteratedDataSnapshot) => boolean | void): boolean;
155155
```
156156

157157
### Parameters
158158

159159
| Parameter | Type | Description |
160160
| --- | --- | --- |
161-
| action | (child: [DataSnapshot](./database.datasnapshot.md#datasnapshot_class)<!-- -->) =&gt; boolean \| void | A function that will be called for each child DataSnapshot. The callback can return true to cancel further enumeration. |
161+
| action | (child: [IteratedDataSnapshot](./database.iterateddatasnapshot.md#iterateddatasnapshot_interface)<!-- -->) =&gt; boolean \| void | A function that will be called for each child DataSnapshot. The callback can return true to cancel further enumeration. |
162162

163163
<b>Returns:</b>
164164

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Project: /docs/reference/js/_project.yaml
2+
Book: /docs/reference/_book.yaml
3+
page_type: reference
4+
5+
{% comment %}
6+
DO NOT EDIT THIS FILE!
7+
This is generated by the JS SDK team, and any local changes will be
8+
overwritten. Changes should be made in the source code at
9+
https://github.com/firebase/firebase-js-sdk
10+
{% endcomment %}
11+
12+
# IteratedDataSnapshot interface
13+
Represents a child snapshot of a `Reference` that is being iterated over. The key will never be undefined.
14+
15+
<b>Signature:</b>
16+
17+
```typescript
18+
export declare interface IteratedDataSnapshot extends DataSnapshot
19+
```
20+
<b>Extends:</b> [DataSnapshot](./database.datasnapshot.md#datasnapshot_class)
21+
22+
## Properties
23+
24+
| Property | Type | Description |
25+
| --- | --- | --- |
26+
| [key](./database.iterateddatasnapshot.md#iterateddatasnapshotkey) | string | |
27+
28+
## IteratedDataSnapshot.key
29+
30+
<b>Signature:</b>
31+
32+
```typescript
33+
key: string;
34+
```

docs-devsite/database.md

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ Firebase Realtime Database
9494
| Interface | Description |
9595
| --- | --- |
9696
| [DatabaseReference](./database.databasereference.md#databasereference_interface) | A <code>DatabaseReference</code> represents a specific location in your Database and can be used for reading or writing data to that Database location.<!-- -->You can reference the root or child location in your Database by calling <code>ref()</code> or <code>ref(&quot;child/path&quot;)</code>.<!-- -->Writing is done with the <code>set()</code> method and reading can be done with the <code>on*()</code> method. See [https://firebase.google.com/docs/database/web/read-and-write](https://firebase.google.com/docs/database/web/read-and-write) |
97+
| [IteratedDataSnapshot](./database.iterateddatasnapshot.md#iterateddatasnapshot_interface) | Represents a child snapshot of a <code>Reference</code> that is being iterated over. The key will never be undefined. |
9798
| [ListenOptions](./database.listenoptions.md#listenoptions_interface) | An options objects that can be used to customize a listener. |
9899
| [Query](./database.query.md#query_interface) | A <code>Query</code> sorts and filters the data at a Database location so only a subset of the child data is included. This can be used to order a collection of data by some attribute (for example, height of dinosaurs) as well as to restrict a large list of items (for example, chat messages) down to a number suitable for synchronizing to the client. Queries are created by chaining together one or more of the filter methods defined here.<!-- -->Just as with a <code>DatabaseReference</code>, you can receive data from a <code>Query</code> by using the <code>on*()</code> methods. You will only receive events and <code>DataSnapshot</code>s for the subset of the data that matches your query.<!-- -->See [https://firebase.google.com/docs/database/web/lists-of-data\#sorting\_and\_filtering\_data](https://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data) for more information. |
99100
| [ThenableReference](./database.thenablereference.md#thenablereference_interface) | A <code>Promise</code> that can also act as a <code>DatabaseReference</code> when returned by [push()](./database.md#push)<!-- -->. The reference is available immediately and the <code>Promise</code> resolves as the write to the backend completes. |

packages/firebase/compat/index.d.ts

+5-1
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`.
@@ -5998,6 +5998,10 @@ declare namespace firebase.database {
59985998
toJSON(): Object | null;
59995999
}
60006000

6001+
interface IteratedDataSnapshot extends DataSnapshot {
6002+
key: string; // key of the location of this snapshot.
6003+
}
6004+
60016005
/**
60026006
* The Firebase Database service interface.
60036007
*

packages/firestore-types/index.d.ts

+24-8
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,10 @@ export interface GetOptions {
241241
readonly source?: 'default' | 'server' | 'cache';
242242
}
243243

244-
export class DocumentReference<T = DocumentData> {
244+
export class DocumentReference<
245+
T = DocumentData,
246+
T2 extends DocumentData = DocumentData
247+
> {
245248
private constructor();
246249

247250
readonly id: string;
@@ -307,7 +310,10 @@ export interface SnapshotMetadata {
307310
isEqual(other: SnapshotMetadata): boolean;
308311
}
309312

310-
export class DocumentSnapshot<T = DocumentData> {
313+
export class DocumentSnapshot<
314+
T = DocumentData,
315+
T2 extends DocumentData = DocumentData
316+
> {
311317
protected constructor();
312318

313319
readonly exists: boolean;
@@ -323,8 +329,9 @@ export class DocumentSnapshot<T = DocumentData> {
323329
}
324330

325331
export class QueryDocumentSnapshot<
326-
T = DocumentData
327-
> extends DocumentSnapshot<T> {
332+
T = DocumentData,
333+
T2 extends DocumentData = DocumentData
334+
> extends DocumentSnapshot<T, T2> {
328335
private constructor();
329336

330337
data(options?: SnapshotOptions): T;
@@ -344,7 +351,7 @@ export type WhereFilterOp =
344351
| 'array-contains-any'
345352
| 'not-in';
346353

347-
export class Query<T = DocumentData> {
354+
export class Query<T = DocumentData, T2 extends DocumentData = DocumentData> {
348355
protected constructor();
349356

350357
readonly firestore: FirebaseFirestore;
@@ -409,7 +416,10 @@ export class Query<T = DocumentData> {
409416
withConverter<U>(converter: FirestoreDataConverter<U>): Query<U>;
410417
}
411418

412-
export class QuerySnapshot<T = DocumentData> {
419+
export class QuerySnapshot<
420+
T = DocumentData,
421+
T2 extends DocumentData = DocumentData
422+
> {
413423
private constructor();
414424

415425
readonly query: Query<T>;
@@ -430,14 +440,20 @@ export class QuerySnapshot<T = DocumentData> {
430440

431441
export type DocumentChangeType = 'added' | 'removed' | 'modified';
432442

433-
export interface DocumentChange<T = DocumentData> {
443+
export interface DocumentChange<
444+
T = DocumentData,
445+
T2 extends DocumentData = DocumentData
446+
> {
434447
readonly type: DocumentChangeType;
435448
readonly doc: QueryDocumentSnapshot<T>;
436449
readonly oldIndex: number;
437450
readonly newIndex: number;
438451
}
439452

440-
export class CollectionReference<T = DocumentData> extends Query<T> {
453+
export class CollectionReference<
454+
T = DocumentData,
455+
T2 extends DocumentData = DocumentData
456+
> extends Query<T, T2> {
441457
private constructor();
442458

443459
readonly id: string;

0 commit comments

Comments
 (0)