I am new to using TypeScript and I could really use some help. I'm stuck on how to fix this error.
Interfaces
export interface IProduct {
name: string;
price: number[];
stock: number;
createdAt: firestore.Timestamp
}
export interface IDataProduct {
[key: string]: IProduct
}
Retrieve ProductList from Firestore
export const fetchProducts = () =>
async (dispatch: Dispatch, getState: () => any, { db }: IServices) => {
try {
const snaps = await db.collection('productos').get()
let products: IDataProduct = {}
snaps.forEach(x => {
return products[x.id] = x.data()
})
dispatch(fetchSuccess(products))
} catch (error) { dispatch(fetchError(error)) }
}
The error
" Type 'DocumentData' is not assignable to type 'IProduct'.
Type 'DocumentData' is missing the following properties from type 'IProduct': name, precio, stock, createdAt "
is found here return products[x.id] = x.data()
x object
{
id: "IgzlwT6OlazrlBTmAIj4"
ref: (...)
exists: (...)
metadata: t
im: t {xT: FirebaseAppImpl, BT: t, INTERNAL: {…}, OT: t, WT: "[DEFAULT]", …}
em: t {path: n}
lm: n {key: t, version: t, Ee: t, te: false, hasCommittedMutations: false}
dm: false
fm: false
om: undefined
__proto__: t
}
and x.data() returns
{
stock: 64
name: "ProductName 50Kg"
price: (3) [24, 23, 20]
createdAt: t {seconds: 1587099600, nanoseconds: 0}
}
I'm having trouble resolving this issue