Skip to content

Commit 75930f8

Browse files
authored
Merge pull request microsoft#25699 from Microsoft/revert-explicitly-typed-special-assignments
Revert explicitly typed special assignments
2 parents d690835 + 16676f2 commit 75930f8

13 files changed

+59
-617
lines changed

src/compiler/checker.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4714,10 +4714,6 @@ namespace ts {
47144714
// function/class/{} assignments are fresh declarations, not property assignments, so only add prototype assignments
47154715
const specialDeclaration = getAssignedJavascriptInitializer(symbol.valueDeclaration);
47164716
if (specialDeclaration) {
4717-
const tag = getJSDocTypeTag(specialDeclaration);
4718-
if (tag && tag.typeExpression) {
4719-
return getTypeFromTypeNode(tag.typeExpression);
4720-
}
47214717
return getWidenedLiteralType(checkExpressionCached(specialDeclaration));
47224718
}
47234719
const types: Type[] = [];
@@ -5085,7 +5081,7 @@ namespace ts {
50855081
}
50865082

50875083
function getJSInitializerType(decl: Node, symbol: Symbol, init: Expression | undefined): Type | undefined {
5088-
if (init && isInJavaScriptFile(init) && isObjectLiteralExpression(init) && init.properties.length === 0) {
5084+
if (init && isInJavaScriptFile(init) && isObjectLiteralExpression(init)) {
50895085
const exports = createSymbolTable();
50905086
while (isBinaryExpression(decl) || isPropertyAccessExpression(decl)) {
50915087
const s = getSymbolOfNode(decl);
@@ -15790,22 +15786,22 @@ namespace ts {
1579015786
}
1579115787

1579215788
// In an assignment expression, the right operand is contextually typed by the type of the left operand.
15793-
// 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.
1579415790
function isContextSensitiveAssignment(binaryExpression: BinaryExpression): boolean {
1579515791
const kind = getSpecialPropertyAssignmentKind(binaryExpression);
1579615792
switch (kind) {
1579715793
case SpecialPropertyAssignmentKind.None:
1579815794
return true;
1579915795
case SpecialPropertyAssignmentKind.Property:
15800-
case SpecialPropertyAssignmentKind.ExportsProperty:
15801-
case SpecialPropertyAssignmentKind.Prototype:
15802-
case SpecialPropertyAssignmentKind.PrototypeProperty:
1580315796
// If `binaryExpression.left` was assigned a symbol, then this is a new declaration; otherwise it is an assignment to an existing declaration.
1580415797
// See `bindStaticPropertyAssignment` in `binder.ts`.
15805-
return !binaryExpression.left.symbol || binaryExpression.left.symbol.valueDeclaration && !!getJSDocTypeTag(binaryExpression.left.symbol.valueDeclaration);
15806-
case SpecialPropertyAssignmentKind.ThisProperty:
15798+
return !binaryExpression.left.symbol;
15799+
case SpecialPropertyAssignmentKind.ExportsProperty:
1580715800
case SpecialPropertyAssignmentKind.ModuleExports:
15808-
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;
1580915805
default:
1581015806
return Debug.assertNever(kind);
1581115807
}

tests/baselines/reference/chainedPrototypeAssignment.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ A.prototype = B.prototype = {
8686
>A : typeof A
8787
>prototype : { [x: string]: any; m(n: number): number; }
8888
>B.prototype = { /** @param {number} n */ m(n) { return n + 1 }} : { [x: string]: any; m(n: number): number; }
89-
>B.prototype : { [x: string]: any; m(n: number): number; }
89+
>B.prototype : { [x: string]: any; }
9090
>B : typeof B
91-
>prototype : { [x: string]: any; m(n: number): number; }
91+
>prototype : { [x: string]: any; }
9292
>{ /** @param {number} n */ m(n) { return n + 1 }} : { [x: string]: any; m(n: number): number; }
9393

9494
/** @param {number} n */

tests/baselines/reference/conflictingCommonJSES2015Exports.types

Lines changed: 2 additions & 2 deletions
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

Lines changed: 0 additions & 89 deletions
This file was deleted.

tests/baselines/reference/contextualTypedSpecialAssignment.symbols

Lines changed: 0 additions & 173 deletions
This file was deleted.

0 commit comments

Comments
 (0)