-
Notifications
You must be signed in to change notification settings - Fork 64
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
Add TypeScript declarations #13
Conversation
TContext | ||
> { | ||
protected collection: Collection<TData> | ||
protected model: Model<TData> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is only sometimes defined—should it be model?
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we change this to model?
, then in a project which uses mongoose
, devs would have to do this.model?.someMethod
or this.model && this.model.someMethod
.
As seen on line 14, this is going to conditionally have type MongooseModel<T>
(if the class is specialized with a mongoose collection) or never
if the constructor is specialized with a mongo collection)
Maybe I should change line 14 to this:
export type Model<T> = T extends Document ? MongooseModel<T> : undefined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After this change ^
this.model
will have type:
MongooseModel<T>
if constructor is passed aMongooseModel<T>
undefined
if we're using aMongoCollection
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds more accurate than never? whatever you think best
Thanks! Released in |
@lorensr I'm not sure why
npm install
triggered a massive change in the lock file.I have a project that I'm working on (it's private), and I'm using
mongodb
collections in that project. It works to the best of my knowledge.Any feedback is appreciated! 😃