【发布时间】:2022-01-22 01:35:33
【问题描述】:
我有以下模型架构接口:
import { Document } from 'mongoose';
export interface ILog {
tags: { [key: string]: string }[];
}
export interface ILogDocument extends ILog, Document {}
还有架构:
const logSchema = new Schema<ILogDocument>({
tags: { type: Map, of: String },
});
所以我的架构出现以下类型错误:
TS2322: Type '{ type: MapConstructor; of: StringConstructor; }' is not assignable to type 'SchemaDefinitionProperty<{ [key: string]: string; }[]> | undefined'.
我想使用正确的类型定义,我尝试了type: Schema.Types.Mixed 及其作品,但是有没有更好的方法来为tags: { [key: string]: string }[] 指定猫鼬类型?
【问题讨论】:
标签: node.js typescript mongodb mongoose mongoose-schema