-
Notifications
You must be signed in to change notification settings - Fork 962
Closed
Description
[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; |
firebase-js-sdk/packages/firebase/compat/index.d.ts
Lines 5821 to 5823 in efe2000
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?