-
-
Notifications
You must be signed in to change notification settings - Fork 135
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
Automatic populate assertion with type inference #896
Comments
to confirm, did you test the code? the types look reasonable, but there are some small problems:
|
Yes I tested it but just manually in some functions I have inside the branch where I created this assertPopulated function. I used ChatGPT for the complex types because I couldnt have created them myself fastly. Regarding your points:
Anyway this was just an experiment to be refined here with you as I am not as expert as you in typescript and typegoose :) |
is this in context of the following?
when yes, this refers to Line 17 in 766134b
|
Describe what you need | want
So I have been writing a lot of
isDocument
inside my functions to early return if some properties are not previously populated when passing a document instance as parameter. I would like to not only check for those properties populated but already populate them if they arent, but I dont want to always populate those fields because its not always required, so no need for mongoose-autopopulateDo you have already an idea for the implementation?
With the help of ChatGPT I think I have found a solution to this with this
assertPopulated
utility function. I am not a typescript expert so if you think this can be improved it would be a great help:Example usage:
In my case I have a BaseEntity model, but it should also work with the base
Document
type from mongoose. This is the BaseEntity in case anyone is interested:What do you think? @hasezoey If you think this is correct and useful, feel free to add it to the documentation, or I can just open a PR to do it!
The text was updated successfully, but these errors were encountered: