node.js - 错误 TS2322:类型“任何”不可分配给类型“从不”
问题描述
我正在使用"typescript"- "3.8.3"
,"mongoose": "5.9.11"
我的代码正在处理版本"typescript": "3.4.x"
, "mongoose": "4.x"
。
Collections
如下:
export let Collections = {
identity: "identities",
calllog: "calllog",
calllogs: "calllogs"
};
我经历了一些相关的错误> TypeScript/issues/31663,但不知道如何解决它。
解决方案
问题在于传递给 model< any > 和 Schema的类型
我创建的界面如下:
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
}]
})
);
繁荣它开始工作。
推荐阅读
- javascript - 选择器数据从 redux 存储中正确加载,但调用页面组件未显示
- javascript - 根据下面提到的代码,xpath 的“text()”属性不适用于通过 Selenium 的文本节点
- python-3.x - 如何在 Discord 中发送嵌入到直接消息?
- storybook - 指定 Storybook 的默认页面
- swift - 在 Watchkit 表格行中看不到 Spritekit 场景
- html - Spring boot 请求的映射值变量
- sql - PostgreSQL - 类似的替代品,包含
- reactjs - Wordpress Gutenberg React – 使用 HTML 渲染变量
- reactjs - 如果状态没有变化,则强制重新加载反应 js 组件
- typescript - 为什么这个包装的样式组件错误“没有共同的属性”