-
Notifications
You must be signed in to change notification settings - Fork 392
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
null | string
is not a valid disjoint type
#32
Comments
This is not a bug, but a behavior in TS<2.
At most, we should add a readme note here. Biting my tongue, I expect that in a few months most people will have switched onto TS2. |
If you're curious, see microsoft/TypeScript#7140 and microsoft/TypeScript#8652 - these have not yet made it into the language spec. |
Thanks for the explaination. |
FYI: If someone comes across this, I am on typescript 2.0.3 and I can confirm this is no longer an issue. |
I made a mistake in part of the test case requested for #27.
json-schema-to-typescript/test/cases/disjoint-type.ts
Line 19 in b6820b5
Unions of other simple types are being handled nicely - thank you again for adding this capability. But I didn't realize until having
tsc
complain and then reading How to declare a type as nullable in TypeScript? (which coincidentally @bcherny submitted an answer) that theanotherValue?: null | string;
is not valid typescript. After reading the answers to this stackoverflow question I realize that anytime there are disjoint types for a property that includesnull
, thennull
should be filtered from the list of types and the property should become optional (which in the example test case coincidentally was).Would you agree this is a correct interpretation of how to translate a disjoint type with
null
in its list and transforming to a typescript interface? (If not, it's still a bug becausenull | string
is not valid according totsc
. So I am open to other suggestions of how to handle disjoint types withnull
in it.)BTW: I saw this deeper in the comments of the above stackoverflow question: microsoft/TypeScript#7140. So it looks like this is just a bug with
tsc
<2.0
.The text was updated successfully, but these errors were encountered: