[REQUIRED] Describe your environment
- Operating System version: N/A
- Browser version: N/A
- Firebase SDK version: 9.8
- Firebase Product: database
[REQUIRED] Describe the problem
When using DataSnapshot#forEach the parameter available to the action closure is a DataSnapshot which is correct, but the key property of this value has the type string | null, but as its a child of the iterating snapshot it can't be the root node so its key can never be null.
Steps to reproduce:
const node = await getDatabase().ref().get()
node.forEach(child => {
const key = child.key
// key is possibly null so have to cast etc.
})
Relevant Code:
|
forEach(action: (a: DataSnapshot) => boolean | void): boolean; |
|
forEach( |
|
action: (a: firebase.database.DataSnapshot) => boolean | void |
|
): boolean; |
|
forEach(action: (snapshot: DataSnapshot) => boolean | void): boolean { |
Fix
Happy to do a PR for this - I just remember it being a bit complicated last time I did this. Is the info in that issue still correct - the function signature in the above 3 places just needs to be changed?
Would changing the function signature to forEach(action: (a: DataSnapshot & { key: string }) => boolean | void): boolean; be OK for a fix?
[REQUIRED] Describe your environment
[REQUIRED] Describe the problem
When using
DataSnapshot#forEachthe parameter available to the action closure is aDataSnapshotwhich is correct, but thekeyproperty of this value has the typestring | null, but as its a child of the iterating snapshot it can't be the root node so its key can never benull.Steps to reproduce:
Relevant Code:
firebase-js-sdk/packages/database-types/index.d.ts
Line 25 in efe2000
firebase-js-sdk/packages/firebase/compat/index.d.ts
Lines 5821 to 5823 in efe2000
firebase-js-sdk/packages/database-compat/src/api/Reference.ts
Line 167 in efe2000
Fix
Happy to do a PR for this - I just remember it being a bit complicated last time I did this. Is the info in that issue still correct - the function signature in the above 3 places just needs to be changed?
Would changing the function signature to
forEach(action: (a: DataSnapshot & { key: string }) => boolean | void): boolean;be OK for a fix?