Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b5a39e8

Browse files
committed
Change to more conservative conditional type relationship
1 parent d70d505 commit b5a39e8

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/compiler/checker.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10200,18 +10200,18 @@ namespace ts {
1020010200
}
1020110201
else if (source.flags & TypeFlags.Conditional) {
1020210202
if (target.flags & TypeFlags.Conditional) {
10203-
if (isTypeIdenticalTo((<ConditionalType>source).checkType, (<ConditionalType>target).checkType) &&
10204-
isTypeIdenticalTo((<ConditionalType>source).extendsType, (<ConditionalType>target).extendsType)) {
10203+
// Two conditional types 'T1 extends U1 ? X1 : Y1' and 'T2 extends U2 ? X2 : Y2' are related if
10204+
// one of T1 and T2 is related to the other, U1 and U2 are identical types, X1 is related to X2,
10205+
// and Y1 is related to Y2.
10206+
if (isTypeIdenticalTo((<ConditionalType>source).extendsType, (<ConditionalType>target).extendsType) &&
10207+
(isRelatedTo((<ConditionalType>source).checkType, (<ConditionalType>target).checkType) || isRelatedTo((<ConditionalType>target).checkType, (<ConditionalType>source).checkType))) {
1020510208
if (result = isRelatedTo(getTrueTypeFromConditionalType(<ConditionalType>source), getTrueTypeFromConditionalType(<ConditionalType>target), reportErrors)) {
1020610209
result &= isRelatedTo(getFalseTypeFromConditionalType(<ConditionalType>source), getFalseTypeFromConditionalType(<ConditionalType>target), reportErrors);
1020710210
}
10208-
}
10209-
else {
10210-
result = isRelatedTo(getDefaultConstraintOfConditionalType(<ConditionalType>source), getDefaultConstraintOfConditionalType(<ConditionalType>target), reportErrors);
10211-
}
10212-
if (result) {
10213-
errorInfo = saveErrorInfo;
10214-
return result;
10211+
if (result) {
10212+
errorInfo = saveErrorInfo;
10213+
return result;
10214+
}
1021510215
}
1021610216
}
1021710217
else if (relation !== definitelyAssignableRelation) {

0 commit comments

Comments
 (0)