相关疑难解决方法(0)

Typescript mongoose静态模型方法"属性不存在于类型上"

我目前正在尝试向我的mongoose架构添加一个静态方法,但我找不到它不能以这种方式工作的原因.

我的模特:

import * as bcrypt from 'bcryptjs';
import { Document, Schema, Model, model } from 'mongoose';

import { IUser } from '../interfaces/IUser';

export interface IUserModel extends IUser, Document {
    comparePassword(password: string): boolean;
}

export const userSchema: Schema = new Schema({
    email: { type: String, index: { unique: true }, required: true },
    name: { type: String, index: { unique: true }, required: true },
    password: { type: String, required: true }
});

userSchema.method('comparePassword', function (password: string): boolean {
    if …
Run Code Online (Sandbox Code Playgroud)

mongoose node.js typescript

25
推荐指数
3
解决办法
1万
查看次数

标签 统计

mongoose ×1

node.js ×1

typescript ×1