在将插件添加到架构后,我在控制器中使用分页时遇到问题,我的代码是用typescript 2.1编写的,我在devdependencies中安装了@types/mongoose paginate。
[TS]严重性:“错误”消息:“类型“model”上不存在属性“paginate”。
我的控制器:
export function getAllArtists(req, res) {
Artist.paginate({}, { page: 3, limit: 10 }, function(err, result) {
// ...
// ...
});
我的架构:
'use strict'
import {Document, model, Model, Schema} from 'mongoose';
import * as mongoosePaginate from 'mongoose-paginate';
interface IArtist extends Document {
name: String;
description: String;
image: String;
}
const ArtistSchema: Schema = new Schema({
name: String,
description: String,
image: String
});
ArtistSchema.plugin(mongoosePaginate);
export const ArtistModel: Model<IArtist> = model<IArtist>('Artist', ArtistSchema);
谢谢,
最佳答案
解决方案包括一个接口,它将PyIATATMODEL扩展到我的模式。
'use strict'
import { PaginateModel, Document, Schema, model } from 'mongoose';
import * as mongoosePaginate from 'mongoose-paginate';
interface IArtist extends Document {
name: String;
description: String;
image: String;
}
const ArtistSchema: Schema = new Schema({
name: String,
description: String,
image: String
});
ArtistSchema.plugin(mongoosePaginate);
interface ArtistModel<T extends Document> extends PaginateModel<T> {}
export const ArtistModel: ArtistModel<IArtist> = model<IArtist>('Artist', ArtistSchema);
关于typescript - 在插件中导入架构后调用“paginate”时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42859759/