Typescript mongoose static model method “Property does not exist on type”

后端 未结 5 956
囚心锁ツ
囚心锁ツ 2020-12-12 17:58

I am currently trying to add a static method to my mongoose schema but I can\'t find the reason why it doesn\'t work this way.

My model:

import * as          


        
5条回答
  •  伪装坚强ぢ
    2020-12-12 18:58

    I cannot see your IUser interface however I suspect that you have not included the methods in there. EG

    export interface IUser {
        email: string,
        hash: string,
        salt: string,
    
        setPassword(password: string): void,
        validPassword(password: string): boolean,
        generateJwt(): string
    }
    

    typescript will then recognize your methods and stop complaining

提交回复
热议问题