小编Nic*_* S.的帖子

在打字稿中声明对象数组

我试图声明:

type ArticleModel = {
    _id: number;
    name: string;
}
Run Code Online (Sandbox Code Playgroud)

然后在我的课上:

public models: ArticleModel[];
Run Code Online (Sandbox Code Playgroud)

模型应该在哪里,因为您可能已经猜到了一系列 ArticleModel。

但是 node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js 抛出:

error TS2322: Type 'Object[]' is not assignable to type '{ _id: number; name: string; }[]'.
  Type 'Object' is not assignable to type '{ _id: number; name: string; }'.
    Property 'id' is missing in type 'Object'..
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激。

提前致谢。

typescript

0
推荐指数
1
解决办法
1万
查看次数

标签 统计

typescript ×1