错误TS2322:类型“ any”不能分配给类型“ never”

时间:2020-05-02 08:27:57

标签: node.js typescript mongoose

我正在使用"typescript"- "3.8.3""mongoose": "5.9.11"

我的代码正在使用"typescript": "3.4.x""mongoose": "4.x"版本。

我的代码段如下: enter image description here

其中Collections如下:

export let Collections = {
  identity: "identities",
  calllog: "calllog",
  calllogs: "calllogs"
};

我遇到了一些相关的错误> TypeScript/issues/31663,但是对解决该问题的想法并不明确。

1 个答案:

答案 0 :(得分:0)

问题的类型传递给模型<< strong>任何>和模式

我创建了如下界面:

import {Document, Types} from "mongoose";
export interface CallLogsInterface extends Document {
    user: Types.ObjectId,
    logs: Types.ObjectId []
}

并将接口传递给模型:

export const ModelCalllogs = model<CallLogsInterface>(
  Collections.calllogs,
  new Schema<CallLogsInterface>({
    user: {
      type: Schema.Types.ObjectId,
      required: true,
      ref: Collections.identity
    },
    logs: [{
      type: Schema.Types.ObjectId,
      required: true,
      ref: Collections.calllog
    }]
  })
);

动臂开始工作。