Fixed a regression with discriminating unions based on a union property against undefined with strictNullChecks: false
#49648
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.
fixes #49643
It's a regression from: 78ef3e7
Previously the first part of the condition was returning
truein theisTypeRelatedTohere (called fromnarrowTypeByDiscriminantbyisTypeComparableTo):https://github.dev/microsoft/TypeScript/blob/8636adbbb9ab47bb377bd89a3390a13b66df34d2/src/compiler/checker.ts#L18248-L18250
It was passing because unions were not ignored by this condition here:
78ef3e7#diff-d9ab6589e714c71e657f601cf30ff51dfc607fc98419bf72e04f6b0fa92cc4b8L17910
Since the mentioned commit explicitly started to ignore unions there and the comment was put in place about it the code followed along through this call:
https://github.dev/microsoft/TypeScript/blob/8636adbbb9ab47bb377bd89a3390a13b66df34d2/src/compiler/checker.ts#L18263-L18265
and a union member has started to be tested through the condition I've adjusted now. The fix was needed here because this condition was not checking the "reversed" relation (
isSimpleTypeRelatedTo(originalTarget, originalSource, relation)) in the case of thecomparableRelation.cc @nicolo-ribaudo