Skip to content

Commit 16676f2

Browse files
committed
Revert "Explicitly typed special assignments are context sensitive (#25619)"
This reverts commit 32e60a9.
1 parent ff8c30d commit 16676f2

7 files changed

+22
-579
lines changed

src/compiler/checker.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -15786,22 +15786,22 @@ namespace ts {
1578615786
}
1578715787

1578815788
// In an assignment expression, the right operand is contextually typed by the type of the left operand.
15789-
// Don't do this for special property assignments unless there is a type tag on the assignment, to avoid circularity from checking the right operand.
15789+
// Don't do this for special property assignments to avoid circularity.
1579015790
function isContextSensitiveAssignment(binaryExpression: BinaryExpression): boolean {
1579115791
const kind = getSpecialPropertyAssignmentKind(binaryExpression);
1579215792
switch (kind) {
1579315793
case SpecialPropertyAssignmentKind.None:
1579415794
return true;
1579515795
case SpecialPropertyAssignmentKind.Property:
15796-
case SpecialPropertyAssignmentKind.ExportsProperty:
15797-
case SpecialPropertyAssignmentKind.Prototype:
15798-
case SpecialPropertyAssignmentKind.PrototypeProperty:
1579915796
// If `binaryExpression.left` was assigned a symbol, then this is a new declaration; otherwise it is an assignment to an existing declaration.
1580015797
// See `bindStaticPropertyAssignment` in `binder.ts`.
15801-
return !binaryExpression.left.symbol || binaryExpression.left.symbol.valueDeclaration && !!getJSDocTypeTag(binaryExpression.left.symbol.valueDeclaration);
15802-
case SpecialPropertyAssignmentKind.ThisProperty:
15798+
return !binaryExpression.left.symbol;
15799+
case SpecialPropertyAssignmentKind.ExportsProperty:
1580315800
case SpecialPropertyAssignmentKind.ModuleExports:
15804-
return !binaryExpression.symbol || binaryExpression.symbol.valueDeclaration && !!getJSDocTypeTag(binaryExpression.symbol.valueDeclaration);
15801+
case SpecialPropertyAssignmentKind.PrototypeProperty:
15802+
case SpecialPropertyAssignmentKind.ThisProperty:
15803+
case SpecialPropertyAssignmentKind.Prototype:
15804+
return false;
1580515805
default:
1580615806
return Debug.assertNever(kind);
1580715807
}

tests/baselines/reference/conflictingCommonJSES2015Exports.types

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ export function abc(a, b, c) { return 5; }
77
>5 : 5
88

99
module.exports = { abc };
10-
>module.exports = { abc } : { abc: (a: any, b: any, c: any) => number; }
10+
>module.exports = { abc } : { [x: string]: any; abc: (a: any, b: any, c: any) => number; }
1111
>module.exports : any
1212
>module : any
1313
>exports : any
14-
>{ abc } : { abc: (a: any, b: any, c: any) => number; }
14+
>{ abc } : { [x: string]: any; abc: (a: any, b: any, c: any) => number; }
1515
>abc : (a: any, b: any, c: any) => number
1616

1717
=== tests/cases/conformance/salsa/use.js ===

tests/baselines/reference/contextualTypedSpecialAssignment.errors.txt

-92
This file was deleted.

tests/baselines/reference/contextualTypedSpecialAssignment.symbols

-173
This file was deleted.

0 commit comments

Comments
 (0)