Skip to content

Commit

Permalink
Updated type of action parameter for DataSnapshot#forEach (#6374)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhodgkins authored Jul 20, 2022
1 parent e4eda86 commit 6583808
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .changeset/kind-pots-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@firebase/database': patch
'@firebase/database-compat': patch
'@firebase/database-types': patch
---

Updated type of action parameter for DataSnapshot#forEach
4 changes: 3 additions & 1 deletion common/api-review/database.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export class DataSnapshot {
child(path: string): DataSnapshot;
exists(): boolean;
exportVal(): any;
forEach(action: (child: DataSnapshot) => boolean | void): boolean;
forEach(action: (child: DataSnapshot & {
key: string;
}) => boolean | void): boolean;
hasChild(path: string): boolean;
hasChildren(): boolean;
get key(): string | null;
Expand Down
4 changes: 3 additions & 1 deletion packages/database-compat/src/api/Reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ export class DataSnapshot implements Compat<ModularDataSnapshot> {
* @returns True if forEach was canceled by action returning true for
* one of the child nodes.
*/
forEach(action: (snapshot: DataSnapshot) => boolean | void): boolean {
forEach(
action: (snapshot: DataSnapshot & { key: string }) => boolean | void
): boolean {
validateArgCount('DataSnapshot.forEach', 1, 1, arguments.length);
validateCallback('DataSnapshot.forEach', 'action', action, false);
return this._delegate.forEach(expDataSnapshot =>
Expand Down
4 changes: 3 additions & 1 deletion packages/database-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export interface DataSnapshot {
child(path: string): DataSnapshot;
exists(): boolean;
exportVal(): any;
forEach(action: (a: DataSnapshot) => boolean | void): boolean;
forEach(
action: (a: DataSnapshot & { key: string }) => boolean | void
): boolean;
getPriority(): string | number | null;
hasChild(path: string): boolean;
hasChildren(): boolean;
Expand Down
4 changes: 3 additions & 1 deletion packages/database/src/api/Reference_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,9 @@ export class DataSnapshot {
* @returns true if enumeration was canceled due to your callback returning
* true.
*/
forEach(action: (child: DataSnapshot) => boolean | void): boolean {
forEach(
action: (child: DataSnapshot & { key: string }) => boolean | void
): boolean {
if (this._node.isLeafNode()) {
return false;
}
Expand Down
4 changes: 3 additions & 1 deletion packages/firebase/compat/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5819,7 +5819,9 @@ declare namespace firebase.database {
* returning true.
*/
forEach(
action: (a: firebase.database.DataSnapshot) => boolean | void
action: (
a: firebase.database.DataSnapshot & { key: string }
) => boolean | void
): boolean;
/**
* Gets the priority value of the data in this `DataSnapshot`.
Expand Down

0 comments on commit 6583808

Please sign in to comment.