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

Plans on releasing a TypeScript type? #6

Closed
tomcanac opened this issue Mar 20, 2020 · 6 comments · Fixed by #8
Closed

Plans on releasing a TypeScript type? #6

tomcanac opened this issue Mar 20, 2020 · 6 comments · Fixed by #8
Assignees

Comments

@tomcanac
Copy link

Hi, everything is in the question:

Are there any plans on doing a TypeScript definition? Would be amazing to have the autocompletion features and validation.

Thanks for any information :)
Tom

@riyadhalnur
Copy link
Owner

Definitely something worth introducing. Thanks for the suggestion.

@riyadhalnur
Copy link
Owner

I released a new version of this plugin v1.1.0 that adds types. Please try it out and let me know if it works for your use case. Cheers!

@tomcanac
Copy link
Author

Hi,

I do have some problems here, I put them here, let me know if you think this is the type definition or my implementation.

1- I used import mongooseSoftDelete from "mongoose-softdelete"; instead of require, because with Require, TS seems to cast the plugin to a type of any (thus, deactivating TS type). So here is my first not-by-the-doc line.

2- I tried to import the plugin in my root mongoose file and apply this to the mongoose global object, like this:

  mongoose.connect(uri, connectionParams);
  mongoose.plugin(mongooseSoftDelete);

and It gives me this warning:

Argument of type 'typeof import("/home/user/work/project-api/node_modules/mongoose-softdelete/index")' is not assignable to parameter of type '(schema: Schema<any>) => void'.
  Type 'typeof import("/home/user/work/projet-api/node_modules/mongoose-softdelete/index")' provides no match for the signature '(schema: Schema<any>): void'.ts(2345)

Note that even when I add the plugin directly to my schemas, It gives me the same warning.

Do you experience the same errors or does it looks like it is on my side?
Thanks for the help!

@riyadhalnur riyadhalnur reopened this Mar 31, 2020
@madeindjs
Copy link
Contributor

I resolved typing issue with this

import softDelete from 'mongoose-softdelete';
// ...
userSchema.plugin(softDelete as () => Schema<any>);

Also maybe it is simplier to make a PR on https://github.com/DefinitelyTyped/DefinitelyTyped ?

@riyadhalnur
Copy link
Owner

@madeindjs PRs are always welcomed 😃

@madeindjs madeindjs mentioned this issue Aug 14, 2020
@madeindjs
Copy link
Contributor

@riyadhalnur , I made a simple PR 😉

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

Successfully merging a pull request may close this issue.

3 participants