From 65838089da47965e5e39e58c76a81a74666b215e Mon Sep 17 00:00:00 2001 From: Rich Hodgkins Date: Wed, 20 Jul 2022 23:54:51 +0100 Subject: [PATCH] Updated type of action parameter for DataSnapshot#forEach (#6374) --- .changeset/kind-pots-admire.md | 7 +++++++ common/api-review/database.api.md | 4 +++- packages/database-compat/src/api/Reference.ts | 4 +++- packages/database-types/index.d.ts | 4 +++- packages/database/src/api/Reference_impl.ts | 4 +++- packages/firebase/compat/index.d.ts | 4 +++- 6 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 .changeset/kind-pots-admire.md diff --git a/.changeset/kind-pots-admire.md b/.changeset/kind-pots-admire.md new file mode 100644 index 00000000000..40cd53310c7 --- /dev/null +++ b/.changeset/kind-pots-admire.md @@ -0,0 +1,7 @@ +--- +'@firebase/database': patch +'@firebase/database-compat': patch +'@firebase/database-types': patch +--- + +Updated type of action parameter for DataSnapshot#forEach diff --git a/common/api-review/database.api.md b/common/api-review/database.api.md index 8b3ef1ac7fb..5ce1fbeaf80 100644 --- a/common/api-review/database.api.md +++ b/common/api-review/database.api.md @@ -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; diff --git a/packages/database-compat/src/api/Reference.ts b/packages/database-compat/src/api/Reference.ts index 3f9bb63b8ff..e2bbef4ef26 100644 --- a/packages/database-compat/src/api/Reference.ts +++ b/packages/database-compat/src/api/Reference.ts @@ -164,7 +164,9 @@ export class DataSnapshot implements Compat { * @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 => diff --git a/packages/database-types/index.d.ts b/packages/database-types/index.d.ts index 680a4a540b8..55d3d236f96 100644 --- a/packages/database-types/index.d.ts +++ b/packages/database-types/index.d.ts @@ -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; diff --git a/packages/database/src/api/Reference_impl.ts b/packages/database/src/api/Reference_impl.ts index 486b7cdce83..3a54a6ec725 100644 --- a/packages/database/src/api/Reference_impl.ts +++ b/packages/database/src/api/Reference_impl.ts @@ -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; } diff --git a/packages/firebase/compat/index.d.ts b/packages/firebase/compat/index.d.ts index ece18a5d1dd..a946c38ec9a 100644 --- a/packages/firebase/compat/index.d.ts +++ b/packages/firebase/compat/index.d.ts @@ -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`.