-
Notifications
You must be signed in to change notification settings - Fork 198
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 support for conditional type nodes #100
Comments
This is closely related to #71 |
I gave it a try and implemented somewhat working conditional type support. It works for the simple stuff I need and a few more complex use cases and also for basic exclude types but there are also type combinations which don't work at all... I'm not really happy with this implementation so I'm not sure if a pull request makes sense. It feels to complicated and I'm still not sure if it isn't possible to use some TypeScript internals to do all this... But maybe it is an acceptable "good enough for now" solution? I also added some tests which shows what is already working. |
Thank you! I made a PR in #105 so we can look at it easily. It does look a bit complicated but the overall structure (having a parser, tests, ...) is a useful start. |
PR is merged and for my project conditional types are now working very well. Closing the issue. |
Because of YousefED/typescript-json-schema#173 I'm currently trying to migrate to
ts-json-schema-generator
. The first problem I have with the new tool is missing support for conditional type nodes which worked fine with thetypescript-json-schema
tool. Here is a minimal example:When I try to generate the schema for
TestJSON
with this tool then I get this error message:I really like the clean structure of the new tool and it looks pretty straight forward how to implement this feature by adding a
ConditionalTypeNodeParser
class like this:But unfortunately I lack the skills to implement the
createType
method. In theory the method has to check ifnode.checkType
is assignable tonode.extendsType
and then returnsnode.trueType
ornode.falseType
. But I don't know if this assignability check must be written from scratch here or if TypeScript already exposes some functionality to do this. And it gets more complicated if the check type is a union type soTypeName<string | Date>
is resolved to"string" | "object"
in this example.The text was updated successfully, but these errors were encountered: