Skip to content

Commit cfd550e

Browse files
Zzzensandersn
andauthored
Avoid bogus circularity error on context sensitive expando assingment (#50487)
Co-authored-by: Nathan Shively-Sanders <[email protected]>
1 parent e012404 commit cfd550e

9 files changed

+231
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28947,7 +28947,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2894728947
return undefined;
2894828948
}
2894928949
}
28950-
return isInJSFile(decl) ? undefined : getTypeOfExpression(binaryExpression.left);
28950+
return isInJSFile(decl) || decl === binaryExpression.left ? undefined : getTypeOfExpression(binaryExpression.left);
2895128951
}
2895228952
case AssignmentDeclarationKind.ExportsProperty:
2895328953
case AssignmentDeclarationKind.Prototype:
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//// [contextualReturnTypeOfIIFE2.ts]
2+
declare namespace app {
3+
function foo(): void;
4+
}
5+
6+
app.foo.bar = (function () {
7+
const someFun = (arg: number) => {};
8+
return { someFun };
9+
})();
10+
11+
app.foo.bar.someFun(1);
12+
13+
14+
//// [contextualReturnTypeOfIIFE2.js]
15+
app.foo.bar = (function () {
16+
var someFun = function (arg) { };
17+
return { someFun: someFun };
18+
})();
19+
app.foo.bar.someFun(1);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
=== tests/cases/compiler/contextualReturnTypeOfIIFE2.ts ===
2+
declare namespace app {
3+
>app : Symbol(app, Decl(contextualReturnTypeOfIIFE2.ts, 0, 0), Decl(contextualReturnTypeOfIIFE2.ts, 2, 1))
4+
5+
function foo(): void;
6+
>foo : Symbol(foo, Decl(contextualReturnTypeOfIIFE2.ts, 0, 23), Decl(contextualReturnTypeOfIIFE2.ts, 4, 4))
7+
}
8+
9+
app.foo.bar = (function () {
10+
>app.foo.bar : Symbol(app.foo.bar, Decl(contextualReturnTypeOfIIFE2.ts, 2, 1))
11+
>app.foo : Symbol(app.foo, Decl(contextualReturnTypeOfIIFE2.ts, 0, 23), Decl(contextualReturnTypeOfIIFE2.ts, 4, 4))
12+
>app : Symbol(app, Decl(contextualReturnTypeOfIIFE2.ts, 0, 0), Decl(contextualReturnTypeOfIIFE2.ts, 2, 1))
13+
>foo : Symbol(app.foo, Decl(contextualReturnTypeOfIIFE2.ts, 0, 23), Decl(contextualReturnTypeOfIIFE2.ts, 4, 4))
14+
>bar : Symbol(app.foo.bar, Decl(contextualReturnTypeOfIIFE2.ts, 2, 1))
15+
16+
const someFun = (arg: number) => {};
17+
>someFun : Symbol(someFun, Decl(contextualReturnTypeOfIIFE2.ts, 5, 7))
18+
>arg : Symbol(arg, Decl(contextualReturnTypeOfIIFE2.ts, 5, 19))
19+
20+
return { someFun };
21+
>someFun : Symbol(someFun, Decl(contextualReturnTypeOfIIFE2.ts, 6, 10))
22+
23+
})();
24+
25+
app.foo.bar.someFun(1);
26+
>app.foo.bar.someFun : Symbol(someFun, Decl(contextualReturnTypeOfIIFE2.ts, 6, 10))
27+
>app.foo.bar : Symbol(app.foo.bar, Decl(contextualReturnTypeOfIIFE2.ts, 2, 1))
28+
>app.foo : Symbol(app.foo, Decl(contextualReturnTypeOfIIFE2.ts, 0, 23), Decl(contextualReturnTypeOfIIFE2.ts, 4, 4))
29+
>app : Symbol(app, Decl(contextualReturnTypeOfIIFE2.ts, 0, 0), Decl(contextualReturnTypeOfIIFE2.ts, 2, 1))
30+
>foo : Symbol(app.foo, Decl(contextualReturnTypeOfIIFE2.ts, 0, 23), Decl(contextualReturnTypeOfIIFE2.ts, 4, 4))
31+
>bar : Symbol(app.foo.bar, Decl(contextualReturnTypeOfIIFE2.ts, 2, 1))
32+
>someFun : Symbol(someFun, Decl(contextualReturnTypeOfIIFE2.ts, 6, 10))
33+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
=== tests/cases/compiler/contextualReturnTypeOfIIFE2.ts ===
2+
declare namespace app {
3+
>app : typeof app
4+
5+
function foo(): void;
6+
>foo : typeof foo
7+
}
8+
9+
app.foo.bar = (function () {
10+
>app.foo.bar = (function () { const someFun = (arg: number) => {}; return { someFun };})() : { someFun: (arg: number) => void; }
11+
>app.foo.bar : { someFun: (arg: number) => void; }
12+
>app.foo : typeof app.foo
13+
>app : typeof app
14+
>foo : typeof app.foo
15+
>bar : { someFun: (arg: number) => void; }
16+
>(function () { const someFun = (arg: number) => {}; return { someFun };})() : { someFun: (arg: number) => void; }
17+
>(function () { const someFun = (arg: number) => {}; return { someFun };}) : () => { someFun: (arg: number) => void; }
18+
>function () { const someFun = (arg: number) => {}; return { someFun };} : () => { someFun: (arg: number) => void; }
19+
20+
const someFun = (arg: number) => {};
21+
>someFun : (arg: number) => void
22+
>(arg: number) => {} : (arg: number) => void
23+
>arg : number
24+
25+
return { someFun };
26+
>{ someFun } : { someFun: (arg: number) => void; }
27+
>someFun : (arg: number) => void
28+
29+
})();
30+
31+
app.foo.bar.someFun(1);
32+
>app.foo.bar.someFun(1) : void
33+
>app.foo.bar.someFun : (arg: number) => void
34+
>app.foo.bar : { someFun: (arg: number) => void; }
35+
>app.foo : typeof app.foo
36+
>app : typeof app
37+
>foo : typeof app.foo
38+
>bar : { someFun: (arg: number) => void; }
39+
>someFun : (arg: number) => void
40+
>1 : 1
41+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//// [contextualReturnTypeOfIIFE3.ts]
2+
declare namespace app {
3+
var foo: {
4+
bar: {
5+
someFun: (arg: number) => void;
6+
};
7+
};
8+
}
9+
10+
app.foo.bar = (function () {
11+
return { someFun(arg) {} };
12+
})();
13+
14+
app.foo.bar.someFun(1);
15+
16+
17+
//// [contextualReturnTypeOfIIFE3.js]
18+
app.foo.bar = (function () {
19+
return { someFun: function (arg) { } };
20+
})();
21+
app.foo.bar.someFun(1);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
=== tests/cases/compiler/contextualReturnTypeOfIIFE3.ts ===
2+
declare namespace app {
3+
>app : Symbol(app, Decl(contextualReturnTypeOfIIFE3.ts, 0, 0))
4+
5+
var foo: {
6+
>foo : Symbol(foo, Decl(contextualReturnTypeOfIIFE3.ts, 1, 5))
7+
8+
bar: {
9+
>bar : Symbol(bar, Decl(contextualReturnTypeOfIIFE3.ts, 1, 12))
10+
11+
someFun: (arg: number) => void;
12+
>someFun : Symbol(someFun, Decl(contextualReturnTypeOfIIFE3.ts, 2, 10))
13+
>arg : Symbol(arg, Decl(contextualReturnTypeOfIIFE3.ts, 3, 16))
14+
15+
};
16+
};
17+
}
18+
19+
app.foo.bar = (function () {
20+
>app.foo.bar : Symbol(bar, Decl(contextualReturnTypeOfIIFE3.ts, 1, 12))
21+
>app.foo : Symbol(app.foo, Decl(contextualReturnTypeOfIIFE3.ts, 1, 5))
22+
>app : Symbol(app, Decl(contextualReturnTypeOfIIFE3.ts, 0, 0))
23+
>foo : Symbol(app.foo, Decl(contextualReturnTypeOfIIFE3.ts, 1, 5))
24+
>bar : Symbol(bar, Decl(contextualReturnTypeOfIIFE3.ts, 1, 12))
25+
26+
return { someFun(arg) {} };
27+
>someFun : Symbol(someFun, Decl(contextualReturnTypeOfIIFE3.ts, 9, 10))
28+
>arg : Symbol(arg, Decl(contextualReturnTypeOfIIFE3.ts, 9, 19))
29+
30+
})();
31+
32+
app.foo.bar.someFun(1);
33+
>app.foo.bar.someFun : Symbol(someFun, Decl(contextualReturnTypeOfIIFE3.ts, 2, 10))
34+
>app.foo.bar : Symbol(bar, Decl(contextualReturnTypeOfIIFE3.ts, 1, 12))
35+
>app.foo : Symbol(app.foo, Decl(contextualReturnTypeOfIIFE3.ts, 1, 5))
36+
>app : Symbol(app, Decl(contextualReturnTypeOfIIFE3.ts, 0, 0))
37+
>foo : Symbol(app.foo, Decl(contextualReturnTypeOfIIFE3.ts, 1, 5))
38+
>bar : Symbol(bar, Decl(contextualReturnTypeOfIIFE3.ts, 1, 12))
39+
>someFun : Symbol(someFun, Decl(contextualReturnTypeOfIIFE3.ts, 2, 10))
40+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
=== tests/cases/compiler/contextualReturnTypeOfIIFE3.ts ===
2+
declare namespace app {
3+
>app : typeof app
4+
5+
var foo: {
6+
>foo : { bar: { someFun: (arg: number) => void; }; }
7+
8+
bar: {
9+
>bar : { someFun: (arg: number) => void; }
10+
11+
someFun: (arg: number) => void;
12+
>someFun : (arg: number) => void
13+
>arg : number
14+
15+
};
16+
};
17+
}
18+
19+
app.foo.bar = (function () {
20+
>app.foo.bar = (function () { return { someFun(arg) {} };})() : { someFun(arg: number): void; }
21+
>app.foo.bar : { someFun: (arg: number) => void; }
22+
>app.foo : { bar: { someFun: (arg: number) => void; }; }
23+
>app : typeof app
24+
>foo : { bar: { someFun: (arg: number) => void; }; }
25+
>bar : { someFun: (arg: number) => void; }
26+
>(function () { return { someFun(arg) {} };})() : { someFun(arg: number): void; }
27+
>(function () { return { someFun(arg) {} };}) : () => { someFun(arg: number): void; }
28+
>function () { return { someFun(arg) {} };} : () => { someFun(arg: number): void; }
29+
30+
return { someFun(arg) {} };
31+
>{ someFun(arg) {} } : { someFun(arg: number): void; }
32+
>someFun : (arg: number) => void
33+
>arg : number
34+
35+
})();
36+
37+
app.foo.bar.someFun(1);
38+
>app.foo.bar.someFun(1) : void
39+
>app.foo.bar.someFun : (arg: number) => void
40+
>app.foo.bar : { someFun: (arg: number) => void; }
41+
>app.foo : { bar: { someFun: (arg: number) => void; }; }
42+
>app : typeof app
43+
>foo : { bar: { someFun: (arg: number) => void; }; }
44+
>bar : { someFun: (arg: number) => void; }
45+
>someFun : (arg: number) => void
46+
>1 : 1
47+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @lib: esnext
2+
// @noImplicitAny: true
3+
4+
declare namespace app {
5+
function foo(): void;
6+
}
7+
8+
app.foo.bar = (function () {
9+
const someFun = (arg: number) => {};
10+
return { someFun };
11+
})();
12+
13+
app.foo.bar.someFun(1);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// @lib: esnext
2+
// @noImplicitAny: true
3+
4+
declare namespace app {
5+
var foo: {
6+
bar: {
7+
someFun: (arg: number) => void;
8+
};
9+
};
10+
}
11+
12+
app.foo.bar = (function () {
13+
return { someFun(arg) {} };
14+
})();
15+
16+
app.foo.bar.someFun(1);

0 commit comments

Comments
 (0)