fix(code): generated code for arrays with nullable items #563
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Status
READY
Description
The code generator for arrays outputs ambiguous types, and breaks for nullable array items.
Currently, the generated code looks like:
string | null[]
This is interpreted as "string or an array of null", which is incorrect.
With this fix, the generated code is:
(string | null)[]
This change wraps all array types in parenthesis (
()
). This is not necessarily needed for a single type, but it causes no harm, avoids any ambiguity, and avoids the need for more complex changes to the code generator.I also added a regression test that fails to compile without this fix. I didn't see an existing pattern for regression tests so I came up with something. Let me know if you'd prefer a different approach.
Related PRs
n/a
Todos
Steps to Test or Reproduce