You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do you want to request a feature or report a bug?
Neither a feature request nor a bug, rather a shy cry for help.
What is the current behavior?
I'm trying to use TypeScript to ensure type-safety for the defined models. To that end I'm following the documentation. And while I got most of it working as expected, few unresolved issues remain - and to those I can't find solutions in the official documentation.
Continuing with a user model from the documentation, extended to cover instance methods, query helpers, and virtuals. Take the following snippet:
I'm left with seven TypeScript errors, and no idea how to approach them:
I was searching through the Github Issues but couldn't find any hints here. Searching through Gitter chat logs didn't help much either. I would appreciate any and all hints as to how I can make those pesky errors to go away.
If this was already approached and answered somewhere else, then my apologies!
You could define this in typescript by providing this as first parameter with the correct typing.
function bla(this: User) {
this._id;
}
We are currently working on getting better typings. For this we the next step is to habe automatically typed models, by @mohammad0-0ahmad
I would say we should merge the open PR for the auto typings first and then touch the scope of those functions if necessary. @mohammad0-0ahmad this is not an invitation to also cover this in your PR :). Lets get your PR merged first...
You could define this in typescript by providing this as first parameter with the correct typing.
function bla(this: User) { this._id; }
We are currently working on getting better typings. For this we the next step is to habe automatically typed models, by @mohammad0-0ahmad
I would say we should merge the open PR for the auto typings first and then touch the scope of those functions if necessary. @mohammad0-0ahmad this is not an invitation to also cover this in your PR :). Lets get your PR merged first...
Thanks for the mention @Uzlopak,
I've planned to cover virtuals and some other TS improvements, but in separate PR's to make them easier to get merged.
@Uzlopak@mohammad0-0ahmad
Just had a look at the PR - looks fantastic! I'll close this for now to not pollute the issue tracker. I'll revisit the issue when #11563 / #9715 will be ready.
Do you want to request a feature or report a bug?
Neither a feature request nor a bug, rather a shy cry for help.
What is the current behavior?
I'm trying to use TypeScript to ensure type-safety for the defined models. To that end I'm following the documentation. And while I got most of it working as expected, few unresolved issues remain - and to those I can't find solutions in the official documentation.
Continuing with a
user
model from the documentation, extended to cover instance methods, query helpers, and virtuals. Take the following snippet:I'm left with seven TypeScript errors, and no idea how to approach them:
I was searching through the Github Issues but couldn't find any hints here. Searching through Gitter chat logs didn't help much either. I would appreciate any and all hints as to how I can make those pesky errors to go away.
If this was already approached and answered somewhere else, then my apologies!
Complimentary
tsconfig.json
:Also, if relevant,
eslintrc.cjs
:What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
The text was updated successfully, but these errors were encountered: