Skip to content

Commit 4fc5f6a

Browse files
committed
When binding pattern contextually types x || y, x contextually types y
1 parent 487bd78 commit 4fc5f6a

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18435,11 +18435,13 @@ namespace ts {
1843518435
}
1843618436
return contextSensitive === true ? getTypeOfExpression(left) : contextSensitive;
1843718437
case SyntaxKind.BarBarToken:
18438-
// When an || expression has a contextual type, the operands are contextually typed by that type. When an ||
18439-
// expression has no contextual type, the right operand is contextually typed by the type of the left operand,
18440-
// except for the special case of Javascript declarations of the form `namespace.prop = namespace.prop || {}`
18438+
// When an || expression has a contextual type, the operands are contextually typed by that type, except
18439+
// when that type originates in a binding pattern, the right operand is contextually typed by the type of
18440+
// the left operand. When an || expression has no contextual type, the right operand is contextually typed
18441+
// by the type of the left operand, except for the special case of Javascript declarations of the form
18442+
// `namespace.prop = namespace.prop || {}`.
1844118443
const type = getContextualType(binaryExpression, contextFlags);
18442-
return !type && node === right && !isDefaultedExpandoInitializer(binaryExpression) ?
18444+
return node === right && (type && type.pattern || !type && !isDefaultedExpandoInitializer(binaryExpression)) ?
1844318445
getTypeOfExpression(left) : type;
1844418446
case SyntaxKind.AmpersandAmpersandToken:
1844518447
case SyntaxKind.CommaToken:

0 commit comments

Comments
 (0)