I have the following snapshot:
const [tasks, setTasks] = useState<[ITask]|[]>([]);
useEffect(() => {
onSnapshot(q, (snapshop) => {
setTasks(
snapshop.docs.map((doc) => ({
...doc.data(),
id: doc.id,
timestamp: doc.data().timestamp?.toDate().getTime(),
}))
);
setLoading(false);
});
}, []);
and the following interface:
interface ITask {
id: string;
foo: string;
bar: string;
timestamp: number;
}
This gives me this error:
Argument of type '{ id: string; timestamp: any; }[]' is not assignable to parameter of type 'SetStateAction<[ITask] | []>'.
Type '{ id: string; timestamp: any; }[]' is not assignable to type '(prevState: [ITask] | []) => [ITask] | []'.
Type '{ id: string; timestamp: any; }[]' provides no match for the signature '(prevState: [ITask] | []): [ITask] | []'.
I am able to read and understand the error, but I don't know how to resolve this issue.
How can I tell, what doc.data() is?