Skip to content

Commit b852a05

Browse files
committed
Propagate nonInferrableType in &&, || and ?? operators
1 parent b346f57 commit b852a05

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28332,15 +28332,18 @@ namespace ts {
2833228332
case SyntaxKind.InKeyword:
2833328333
return checkInExpression(left, right, leftType, rightType);
2833428334
case SyntaxKind.AmpersandAmpersandToken:
28335-
return getTypeFacts(leftType) & TypeFacts.Truthy ?
28335+
return leftType === nonInferrableType || rightType === nonInferrableType ? nonInferrableType :
28336+
getTypeFacts(leftType) & TypeFacts.Truthy ?
2833628337
getUnionType([extractDefinitelyFalsyTypes(strictNullChecks ? leftType : getBaseTypeOfLiteralType(rightType)), rightType]) :
2833728338
leftType;
2833828339
case SyntaxKind.BarBarToken:
28339-
return getTypeFacts(leftType) & TypeFacts.Falsy ?
28340+
return leftType === nonInferrableType || rightType === nonInferrableType ? nonInferrableType :
28341+
getTypeFacts(leftType) & TypeFacts.Falsy && leftType !== nonInferrableType ?
2834028342
getUnionType([removeDefinitelyFalsyTypes(leftType), rightType], UnionReduction.Subtype) :
2834128343
leftType;
2834228344
case SyntaxKind.QuestionQuestionToken:
28343-
return getTypeFacts(leftType) & TypeFacts.EQUndefinedOrNull ?
28345+
return leftType === nonInferrableType || rightType === nonInferrableType ? nonInferrableType :
28346+
getTypeFacts(leftType) & TypeFacts.EQUndefinedOrNull && leftType !== nonInferrableType ?
2834428347
getUnionType([getNonNullableType(leftType), rightType], UnionReduction.Subtype) :
2834528348
leftType;
2834628349
case SyntaxKind.EqualsToken:

0 commit comments

Comments
 (0)