我想将 mongodb 从 3.4 升级到 4.0。我正在使用 angularjs。 打字稿版本 - 3.5.1 角度版本 - 1.5.8 猫鼬版本 - 5.12.1
我收到打字稿错误。在所有具有类似实现的文件中。
error TS2344: Type 'DExperience' does not satisfy the constraint 'Document<any, {}>'.
Types of property 'model' are incompatible.
Type '{ <T extends Model<any, {}>>(name: string): T; (name: string): Model<DExperience, {}>; }' is not assignable to type '{ <T extends Model<any, {}>>(name: string): T; (name: string): Model<Document<any, {}>, {}>; }'.
这是我的 package.json 文件
{
"name": "api-server",
"version": "0.0.1",
"dependencies": {
"angular": "^1.5.8",
"bcrypt": "3.0.6",
"body-parser": "1.13.3",
"cloudinary": "^1.4.3",
"co": "4.6.0",
"cors": "^2.8.5",
"express": "4.13.3",
"mongoose": "5.12.1",
"morgan": "^1.7.0",
"node-schedule": "^1.2.5",
"sequelize": "5.10.1",
"standard-error": "1.1.0",
},
"devDependencies": {
"@babel/core": "^7.11.1",
"@babel/preset-env": "^7.11.0",
"@babel/preset-typescript": "^7.10.4",
"@types/angular": "^1.5.20",
"@types/angular-route": "^1.3.3",
"@types/bcrypt": "^1.0.0",
"@types/body-parser": "1.19.0",
"@types/debug": "0.0.29",
"@types/express": "^4.0.34",
"@types/http-status": "^0.2.29",
"@types/jade": "0.0.29",
"@types/jquery": "3.5.1",
"@types/js-yaml": "3.12.5",
"@types/jwt-simple": "^0.5.32",
"@types/mocha": "2.2.40",
"@types/mongoose": "5.0.0",
"@types/node": "^14.0.27",
"@types/node-schedule": "^1.2.0",
"@types/pluralize": "0.0.27",
"@types/qs": "^6.9.4",
"acquit": "0.4.0",
"acquit-ignore": "0.0.3",
"acquit-markdown": "0.0.1",
"babel-core": "^6.26.3",
"babel-loader": "^8.1.0",
"babel-plugin-angularjs-annotate": "^0.10.0",
"cross-env": "^3.1.3",
"css-loader": "^0.26.0",
"detect-port": "^1.0.6",
"dookie": "0.4.1",
"ts-loader": "4.3.1",
"ts-node": "^9.1.1",
"tsconfig-paths": "^3.7.0",
"tslint": "6.1.3",
"tslint-eslint-rules": "^4.0.0",
"typescript": "3.5.1",
"webpack": "4.44.1",
},
RawVendor、RawExperience、Dvendor 和 DExperience 的类型
import mongoose from 'mongoose';
import { DDatabaseInstance, RawDatabaseInstance } from './database-instance';
export interface RawVendor {
name?: string;
description?: string;
createdBy?: mongoose.Types.ObjectId | string;
url?: string;
city?: string;
isVisible?: boolean;
}
export interface RawExperience {
name?: string;
vendor?: mongoose.Types.ObjectId | string;
description?: string;
vendorName?: string;
order?: number;
}
export interface DVendor extends DDatabaseInstance, RawVendor {
validateSync: (paths?: string[]) => any;
}
export interface DExperience extends DDatabaseInstance, RawExperience {
validateSync: (paths?: string[]) => any;
}
这里是database-instance.ts
import mongoose from 'mongoose';
import { Timestamps } from './timestamps';
/**
* A wrapper type around raw hashes that will exist on either POJO database objects or on `mongoose.Document`s.
*/
export interface RawDatabaseInstance extends Timestamps {
_id: mongoose.Types.ObjectId;
}
/**
* A wrapper type around a non-POJO `mongoose.Document`
*/
export interface DDatabaseInstance extends mongoose.Document {
_id: mongoose.Types.ObjectId;
id: string;
get(path: string): any;
}
时间戳.ts
export interface Timestamps {
createdAt: Date;
updatedAt: Date;
}
这是我出错的地方
export interface MVendor extends mongoose.Model<DVendor> {}
export interface MExperience extends mongoose.Model<DExperience> {}