-
Notifications
You must be signed in to change notification settings - Fork 393
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
definitions for schemas w/ typed additionalProperties are not compatible w/ strictNullChecks #235
Comments
This seems like the correct solution to me. Want to PR this behind a |
Awesome - I'll have a crack at a PR, but will ping you if I run into any problems :) |
I've started work on this. In refreshing my memory on this, I think at least for now I'm going to have The reasoning for this is that you can't assume a property exists unless it's defined, and an index signature is saying that any extra properties which may or may not exist should be of type "x". This is actually a bit of a sticky situation; the whole reason TS doesn't treat index signatures by default as
This isn't a problem for defined properties:
Worse-case, someone can complain & we can look to refine the behaviour :) Just wanted to have this written down so that I don't forgot it again 😄 |
This is all based around an attempt to resolve issues like #201, #210, etc
Currently, j2t generates definitions that are not strict mode compatible:
results in
This isn't valid under
strict
, specifically due tostrictNullChecks
.To be valid,
| undefined
needs to be explicitly added.The "downside" to this is that you have to guard against
undefined
:Personally, I actually think this is for the better anyway, given that since you're not requiring
myProp
, it could very well be undefined.This isn't actually a breaking change, since this will only affect code that has
strictNullChecks
, but ifstrictNullChecks
is on, generated definitions would stop compiling anyway, making it a catch-22 😄The implementation on how to support this is the big question - For
package.json
, the fix is easy: usetsType
, but the problem w/ this is it's a complete override, which means its brittle:Desired:
Actual:
Hence, ideally, what we need is a way to append types; I don't really see much of a use-case outside of appending undefined, so I'd be happy w/ something like
"tsCanBeUndefined": true
.Alternatively, a solution that is a bit nicer but more breaking (IMO) would be whenever an interface is generated w/ an index type (other than
any
), to add| undefined
if the interface has any optional properties.The text was updated successfully, but these errors were encountered: