Argument of type '(snap: DataSnapshot) => void' is not assignable to parameter of type '(a: DataSnapshot) => boolean'
The forEach
method in the DataSnapshot
has this signature:
forEach(action: (a: firebase.database.DataSnapshot) => boolean): boolean;
as the action
can return true
to short-circuit the enumeration and return early. If a falsy value is returned, enumeration continues normally. (This is mentioned in the documentation.)
To appease the TypeScript compiler, the simplest solution would be to return false
(to continue enumerating the child snapshots):
database()
.ref("users")
.orderByChild("id")
.on("value", (snapshot) => {
let items = [];
snapshot.forEach((snap) => {
items.push({
uid: snap.val().uid,
username: snap.val().username
});
return false;
});
});