'Best way to defined Mongoose document instance methods in Typescript

Directly from Mongoose 6 documentation:

"...Although you can add instance methods to your document interface, we do not recommend doing so." Mongoose with Typescript

I currently define my Mongoose schemas in the way described in the above link e.g.:

interface IUser {
  name: string;
  email: string;
  organization: Types.ObjectId;
}

But I'd also love to have type checking for my instance methods. If I abide by the warnings from the Mongoose documentation I would do the following:

interface IUserDocument extends IUser {
     isAdmin(userId: Types.ObjectId): boolean
}

Are there any more elegant or suggested ways to solve this or is this the way to handle it? The documentation explains and goes into how to define 'static' model methods but completely foregoes how to handle instance methods.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source