-
Notifications
You must be signed in to change notification settings - Fork 893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rtdb(types): DataSnapshot#forEach - action parameter has null key #6368
Comments
That syntax doesn't quite match v9, but your suggestions should work. For v9, you still need to update
|
If you could create a PR addressing this, that would be great |
@maneesht Can you suggest some syntax that would match please!
Will do! |
If you're looking at the root, then: import { getDatabase } from 'firebase/database';
const rootSnapshot = await get(ref(getDatabase()));
rootSnapshot.forEach(node => {
console.log(node.key);
}); Out of curiosity, are you using v9-compat? (The non-modular version of firebase database) |
Oh I see the syntax of the example. Yes I'm using |
Those 3 places you pointed out are the correct places to change, and although you are not using the v9 API, the compat API actually wraps the v9 API so you may have to change the line @maneesht indicated as well, because the compat
|
Great - thanks both. |
@rhodgkins thank you for your contribution. However, we will have to rollback this change as it is causing a compilation error with AngularFire. We will add this back on the next major release. Until then, I will reopen this for tracking purposes. |
Closing this as it was part of the 10.0 release: https://firebase.google.com/support/release-notes/js#realtime-database |
[REQUIRED] Describe your environment
[REQUIRED] Describe the problem
When using
DataSnapshot#forEach
the parameter available to the action closure is aDataSnapshot
which is correct, but thekey
property 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?The text was updated successfully, but these errors were encountered: