Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

staticMethod, with or without decorator still doesn't work #62

Closed
patarapolw opened this issue Oct 2, 2019 · 3 comments
Closed

staticMethod, with or without decorator still doesn't work #62

patarapolw opened this issue Oct 2, 2019 · 3 comments
Labels
invalid This Issue is invalid (Bug reports, etc) | This is not an issue with Typegoose itself question Qustions about how to use stuff

Comments

@patarapolw
Copy link

patarapolw commented Oct 2, 2019

Versions

  • NodeJS: 10.16.0
  • Typegoose(NPM): 6.0.0 (@typegoose/typegoose)
  • Typegoose(GIT): commithash
  • mongoose: 5.7.3

Code Example

class Post {
  @prop() _id!: string;
  @prop({ required: true, unique: true }) title!: string;
  @prop() date?: Date;
  @prop({ default: [] }) tag!: string[];
  @prop({ required: true }) content!: string;

  async findByQ(q: string, offset: number = 0, limit: number | null = 10, sort?: ISortOptions<Post>) {
    ...
    return {count, data};
  }
}

const PostModel = getModelForClass(Post);
// PostModel.findByQ = new Post().findByQ;  // TypeScript will complain findByQ is not a function, without this line.

Adding decorator @staticMethod doesn't help.

Do you know why it happens?

no

@patarapolw patarapolw added the bug Something isn't working label Oct 2, 2019
@hasezoey hasezoey removed the bug Something isn't working label Oct 2, 2019
@hasezoey
Copy link
Member

hasezoey commented Oct 2, 2019

you know that you must add the word static to the function to be a static function?

static async findByQ, otherwise it is an instance method

-> if it still dosnt work, please comment / reopen

@hasezoey hasezoey added invalid This Issue is invalid (Bug reports, etc) | This is not an issue with Typegoose itself question Qustions about how to use stuff labels Oct 2, 2019
@hasezoey hasezoey closed this as completed Oct 2, 2019
@patarapolw
Copy link
Author

It works, but anyways, typing is wrong to suggest it, to make it seems like it is available on ReturnModelType<typeof Post, unknown>. Should only be shown on DocumentType<Post>.

@hasezoey
Copy link
Member

hasezoey commented Oct 2, 2019

It works, but anyways, typing is wrong to suggest it, to make it seems like it is available on ReturnModelType<typeof Post, unknown>. Should only be shown on DocumentType<Post>.

i know, but without many typescript intermediate types, it is not possible, (how typescript handels some types is still not clear to me)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This Issue is invalid (Bug reports, etc) | This is not an issue with Typegoose itself question Qustions about how to use stuff
Projects
None yet
Development

No branches or pull requests

2 participants