Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Use mongoose model statics object to add method #101

Open
Meir017 opened this issue Mar 22, 2018 · 1 comment
Open

Use mongoose model statics object to add method #101

Meir017 opened this issue Mar 22, 2018 · 1 comment

Comments

@Meir017
Copy link
Contributor

Meir017 commented Mar 22, 2018

by adding static methods to mongoose's schema object it will show how to take advantage of the mongoose.model function even more.
using the function:

function model<T extends Document, U extends Model<T>>

this would require us to create a static method and another type

export type UserSchema = mongoose.Model<UserModel> & {
  someStaticMethod: (arg1: string) => void;
}

and then at the end:

const User = mongoose.model<UserModel, UserSchema>("User", userSchema);
@ifeltsweet
Copy link

ifeltsweet commented Aug 29, 2018

Is it possible to achieve the same with just JSDoc using @typedef and @type annotations? I can't seem to force vscode to understand that I want to use the overridden form of mongoose.model that has two type parameters.

/**
 * @typedef {mongoose.Model<UserModel> & {someStaticMethod: (arg1: string) => void;}} UserSchema
 */

/**
 * @type {UserSchema}
 */
const User = mongoose.model('User', userSchema);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants