-
Notifications
You must be signed in to change notification settings - Fork 26
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
Custom Schema Types #163
Comments
Hey @kjkurtz, interesting use case! In general I do want to find ways to make the generated types a bit more extendable. Let me look into this, could you provide a simple repro? Thanks |
Sure thing! Here is a basic repo where you can run |
Thanks @kjkurtz! So in the current setup in that repo, there isnt any way we can detect that "DateOnly" actually means date, since it doesnt extend from the Mongoose native type Trying to do a sort of custom override isnt trivial here unfortunately, it would require a significant overhaul of the current codebase. |
I did notice a different bug though, the parser thinks that DateOnly is an object, and tries to dig deeper into its subfields. I can push a small fix for this so that it would just be typed as |
In order to handle Dates where we don't care about the time, we have a custom schema type of
DateOnly
that is effectively a wrapper aroundDate
with some validators attached to make sure the time is set to midnight UTC via a plugin.We use a
types.d.ts
file to make Typescript aware of this additional type which so far has worked. Now, when usingmongoose-tsgen
, we get an errorparser: Unknown type detected for field
for any fields using this new custom type.The type looks like the following:
So quite similar to how you are already augmenting for populate. Any ideas on how to effectively do this so types generate correctly for the schemas that use this custom type? Thanks!
The text was updated successfully, but these errors were encountered: