I was wondering how to fix this code, if I change the type of room to string on forEach((room: string) I got this error:
Argument of type '(room: string) => void' is not assignable to parameter of type '(value: unknown, index: number, array: unknown[]) => void'. Types of parameters 'room' and 'value' are incompatible. Type 'unknown' is not assignable to type 'string'.
Otherwise if I leave blank, I had to convert room as string on the line batch.update.
Object.values(users).forEach((room: string) => {
batch.set(firestore.collection('messages').doc(), {
...message,
room,
})
batch.update(firestore.collection('rooms').doc(room), { // if I leave room as `unknow` I have an error here.
...
})
})
What is the correctly way to fix the typing?
Simply declared the callback argument type should just be fine.
Object.values<string>(users).forEach(s => /* ... */)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With