小编And*_*bor的帖子

类型“DocumentData”不可分配给类型“IProduct”

我刚刚开始使用打字稿,我希望你能帮助我,我不知道如何解决这个错误

\n\n

接口

\n\n
export interface IProduct {\n  name: string;\n  price: number[];\n    stock: number;\n    createdAt: firestore.Timestamp\n}\n\nexport interface IDataProduct {\n    [key: string]: IProduct\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

从 firestore 获取 ProductList

\n\n
export const fetchProducts = () => \n    async (dispatch: Dispatch, getState: () => any, { db }: IServices) => {        \n        try {\n            const snaps = await db.collection(\'productos\').get()\n\n            let products: IDataProduct = {}\n            snaps.forEach(x => {\n             return products[x.id] = x.data()\n            })\n\n            dispatch(fetchSucess(products))\n    } catch (error) { dispatch(fetchError(error)) }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

错误\n 类型\'DocumentData\'无法分配给类型\'IProduct\'。\n类型\'DocumentData\'缺少类型\'IProduct\'中的以下属性:name、precio、stock、createdAt …

firebase typescript google-cloud-firestore

5
推荐指数
1
解决办法
3677
查看次数