Fix check for overwritten properties in object spreads#44696
Fix check for overwritten properties in object spreads#44696ahejlsberg merged 4 commits intomainfrom
Conversation
| for (const right of getPropertiesOfType(type)) { | ||
| const left = props.get(right.escapedName); | ||
| const rightType = getTypeOfSymbol(right); | ||
| if (left && !maybeTypeOfKind(rightType, TypeFlags.Nullable) && !(maybeTypeOfKind(rightType, TypeFlags.AnyOrUnknown) && right.flags & SymbolFlags.Optional)) { |
There was a problem hiding this comment.
@sandersn I'm not sure why we were checking nullable and any/unknown flags here. Seems to me any non-optional property that duplicates a property to the left should trigger the error.
There was a problem hiding this comment.
I think there was a corner case where a type that included undefined was actually for an optional property, but wasn't marked as such. For the others, it might be that unknown and (sort of) any include undefined.
We can ship this in the beta and see if people complain. It's likely that with better optionality tracking, this is not a problem.
sandersn
left a comment
There was a problem hiding this comment.
I think it's fine to ship a stricter check to go with the stricter optional properties. If people complain in the beta we can revisit the decision.
| for (const right of getPropertiesOfType(type)) { | ||
| const left = props.get(right.escapedName); | ||
| const rightType = getTypeOfSymbol(right); | ||
| if (left && !maybeTypeOfKind(rightType, TypeFlags.Nullable) && !(maybeTypeOfKind(rightType, TypeFlags.AnyOrUnknown) && right.flags & SymbolFlags.Optional)) { |
There was a problem hiding this comment.
I think there was a corner case where a type that included undefined was actually for an optional property, but wasn't marked as such. For the others, it might be that unknown and (sort of) any include undefined.
We can ship this in the beta and see if people complain. It's likely that with better optionality tracking, this is not a problem.
This PR fixes two issues:
undefined.undefinedfrom a spread property type in--exactOptionalPropertyTypesmode.Fixes #44438.