Update e.set
to accept an array of values and a type + prevent arrays from being spread into e.set
#513
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.
Current behaviour of
e.set
is buggy when spreading an array of values into it, since at runtime it's not possible to tell if an array was spread or the values were passed statically. This causes a mis-match in the cardinality determined statically by typescript and at runtime. If the array happens to be empty, it also causes a runtime error, as the type of the empty set cannot be determined. Eg:This PR prevents arrays from being spread into
e.set
(unless it's a tuple, eg.const strs = ['abc'] as const
), and instead allows the array to be passed directly, along with a type expr, so the empty array case can be handled. The addition of a type arg also means it's no longer necessary to wrap each item of the array for non js primitive types: