[babel 8] ObjectTypeAnnotation
fields must always be arrays
#14465
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.
The fields
indexers
,callProperties
, andinternalSlots
in the nodeObjectTypeAnnotation
are currently marked as optional. This is correct for the builder, they should be optional there.For the TS types, this is not quite correct, because the babel parser always initializes these fields with empty arrays (https://github.com/babel/babel/blob/main/packages/babel-parser/src/plugins/flow/index.js#L1085-L1088).
The only way to set these fields to null is with the builder currently.
The change here is to not mark these fields as optional but instead provide an empty array as a default value. This way the builder still has these params as optional, but cannot be set to
null
anymore.The Typescript types on the other hand now do not mark these fields as optional which is correct, as they are always an array, even if it might be empty.
Do you think this is a reasonable change?
Now, is this breaking? Only the builder might be considered as a breaking change, as it does not allownull
anymore for these fields (see change generator tests). If you think this is breaking enough I could move that behind the BABEL8 flag. Please let me know.After thinking about this a little more I now think this should be considered breaking. Which Flag should I use?
BABEL_TYPES_8_BREAKING
orBABEL_8_BREAKING