Skip to content

Commit a569603

Browse files
authored
Intersection check for empty object type shouldn't cause circularities (microsoft#38673)
* isEmptyAnonymousObjectType shouldn't require full member resolution * Add regression test
1 parent 2cea9d9 commit a569603

File tree

5 files changed

+38
-1
lines changed

5 files changed

+38
-1
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15367,7 +15367,9 @@ namespace ts {
1536715367
}
1536815368

1536915369
function isEmptyAnonymousObjectType(type: Type) {
15370-
return !!(getObjectFlags(type) & ObjectFlags.Anonymous) && isEmptyObjectType(type);
15370+
return !!(getObjectFlags(type) & ObjectFlags.Anonymous && (
15371+
(<ResolvedType>type).members && isEmptyResolvedType(<ResolvedType>type) ||
15372+
type.symbol && type.symbol.flags & SymbolFlags.TypeLiteral && getMembersOfSymbol(type.symbol).size === 0));
1537115373
}
1537215374

1537315375
function isStringIndexSignatureOnlyType(type: Type): boolean {

tests/baselines/reference/intersectionsAndEmptyObjects.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ var myChoicesAndEmpty: choices<IMyChoiceList & {}>;
7575

7676
var unknownChoices: choices<IUnknownChoiceList>;
7777
var unknownChoicesAndEmpty: choices<IUnknownChoiceList & {}>;
78+
79+
// Repro from #38672
80+
81+
type Foo1 = { x: string } & { [x: number]: Foo1 };
82+
type Foo2 = { x: string } & { [K in number]: Foo2 };
7883

7984

8085
//// [intersectionsAndEmptyObjects.js]

tests/baselines/reference/intersectionsAndEmptyObjects.symbols

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,17 @@ var unknownChoicesAndEmpty: choices<IUnknownChoiceList & {}>;
246246
>choices : Symbol(choices, Decl(intersectionsAndEmptyObjects.ts, 51, 19))
247247
>IUnknownChoiceList : Symbol(IUnknownChoiceList, Decl(intersectionsAndEmptyObjects.ts, 64, 2))
248248

249+
// Repro from #38672
250+
251+
type Foo1 = { x: string } & { [x: number]: Foo1 };
252+
>Foo1 : Symbol(Foo1, Decl(intersectionsAndEmptyObjects.ts, 75, 61))
253+
>x : Symbol(x, Decl(intersectionsAndEmptyObjects.ts, 79, 13))
254+
>x : Symbol(x, Decl(intersectionsAndEmptyObjects.ts, 79, 31))
255+
>Foo1 : Symbol(Foo1, Decl(intersectionsAndEmptyObjects.ts, 75, 61))
256+
257+
type Foo2 = { x: string } & { [K in number]: Foo2 };
258+
>Foo2 : Symbol(Foo2, Decl(intersectionsAndEmptyObjects.ts, 79, 50))
259+
>x : Symbol(x, Decl(intersectionsAndEmptyObjects.ts, 80, 13))
260+
>K : Symbol(K, Decl(intersectionsAndEmptyObjects.ts, 80, 31))
261+
>Foo2 : Symbol(Foo2, Decl(intersectionsAndEmptyObjects.ts, 79, 50))
262+

tests/baselines/reference/intersectionsAndEmptyObjects.types

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,14 @@ var unknownChoices: choices<IUnknownChoiceList>;
206206
var unknownChoicesAndEmpty: choices<IUnknownChoiceList & {}>;
207207
>unknownChoicesAndEmpty : { shoes: boolean; food: boolean; }
208208

209+
// Repro from #38672
210+
211+
type Foo1 = { x: string } & { [x: number]: Foo1 };
212+
>Foo1 : Foo1
213+
>x : string
214+
>x : number
215+
216+
type Foo2 = { x: string } & { [K in number]: Foo2 };
217+
>Foo2 : Foo2
218+
>x : string
219+

tests/cases/conformance/types/intersection/intersectionsAndEmptyObjects.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,8 @@ var myChoicesAndEmpty: choices<IMyChoiceList & {}>;
7676

7777
var unknownChoices: choices<IUnknownChoiceList>;
7878
var unknownChoicesAndEmpty: choices<IUnknownChoiceList & {}>;
79+
80+
// Repro from #38672
81+
82+
type Foo1 = { x: string } & { [x: number]: Foo1 };
83+
type Foo2 = { x: string } & { [K in number]: Foo2 };

0 commit comments

Comments
 (0)