diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index fcd96daac8f1c..0a13fa6af014a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15308,7 +15308,9 @@ namespace ts { } function isEmptyAnonymousObjectType(type: Type) { - return !!(getObjectFlags(type) & ObjectFlags.Anonymous) && isEmptyObjectType(type); + return !!(getObjectFlags(type) & ObjectFlags.Anonymous && ( + (type).members && isEmptyResolvedType(type) || + type.symbol && type.symbol.flags & SymbolFlags.TypeLiteral && getMembersOfSymbol(type.symbol).size === 0)); } function isStringIndexSignatureOnlyType(type: Type): boolean { diff --git a/tests/baselines/reference/intersectionsAndEmptyObjects.js b/tests/baselines/reference/intersectionsAndEmptyObjects.js index 4c4161e954419..4ff24248f4690 100644 --- a/tests/baselines/reference/intersectionsAndEmptyObjects.js +++ b/tests/baselines/reference/intersectionsAndEmptyObjects.js @@ -75,6 +75,11 @@ var myChoicesAndEmpty: choices; var unknownChoices: choices; var unknownChoicesAndEmpty: choices; + +// Repro from #38672 + +type Foo1 = { x: string } & { [x: number]: Foo1 }; +type Foo2 = { x: string } & { [K in number]: Foo2 }; //// [intersectionsAndEmptyObjects.js] diff --git a/tests/baselines/reference/intersectionsAndEmptyObjects.symbols b/tests/baselines/reference/intersectionsAndEmptyObjects.symbols index 50fb6f866e70b..39131564a5950 100644 --- a/tests/baselines/reference/intersectionsAndEmptyObjects.symbols +++ b/tests/baselines/reference/intersectionsAndEmptyObjects.symbols @@ -246,3 +246,17 @@ var unknownChoicesAndEmpty: choices; >choices : Symbol(choices, Decl(intersectionsAndEmptyObjects.ts, 51, 19)) >IUnknownChoiceList : Symbol(IUnknownChoiceList, Decl(intersectionsAndEmptyObjects.ts, 64, 2)) +// Repro from #38672 + +type Foo1 = { x: string } & { [x: number]: Foo1 }; +>Foo1 : Symbol(Foo1, Decl(intersectionsAndEmptyObjects.ts, 75, 61)) +>x : Symbol(x, Decl(intersectionsAndEmptyObjects.ts, 79, 13)) +>x : Symbol(x, Decl(intersectionsAndEmptyObjects.ts, 79, 31)) +>Foo1 : Symbol(Foo1, Decl(intersectionsAndEmptyObjects.ts, 75, 61)) + +type Foo2 = { x: string } & { [K in number]: Foo2 }; +>Foo2 : Symbol(Foo2, Decl(intersectionsAndEmptyObjects.ts, 79, 50)) +>x : Symbol(x, Decl(intersectionsAndEmptyObjects.ts, 80, 13)) +>K : Symbol(K, Decl(intersectionsAndEmptyObjects.ts, 80, 31)) +>Foo2 : Symbol(Foo2, Decl(intersectionsAndEmptyObjects.ts, 79, 50)) + diff --git a/tests/baselines/reference/intersectionsAndEmptyObjects.types b/tests/baselines/reference/intersectionsAndEmptyObjects.types index 1dcc904a43592..889ee33d378a2 100644 --- a/tests/baselines/reference/intersectionsAndEmptyObjects.types +++ b/tests/baselines/reference/intersectionsAndEmptyObjects.types @@ -206,3 +206,14 @@ var unknownChoices: choices; var unknownChoicesAndEmpty: choices; >unknownChoicesAndEmpty : { shoes: boolean; food: boolean; } +// Repro from #38672 + +type Foo1 = { x: string } & { [x: number]: Foo1 }; +>Foo1 : Foo1 +>x : string +>x : number + +type Foo2 = { x: string } & { [K in number]: Foo2 }; +>Foo2 : Foo2 +>x : string + diff --git a/tests/cases/conformance/types/intersection/intersectionsAndEmptyObjects.ts b/tests/cases/conformance/types/intersection/intersectionsAndEmptyObjects.ts index 2832a3f36bfa7..00db917b96702 100644 --- a/tests/cases/conformance/types/intersection/intersectionsAndEmptyObjects.ts +++ b/tests/cases/conformance/types/intersection/intersectionsAndEmptyObjects.ts @@ -76,3 +76,8 @@ var myChoicesAndEmpty: choices; var unknownChoices: choices; var unknownChoicesAndEmpty: choices; + +// Repro from #38672 + +type Foo1 = { x: string } & { [x: number]: Foo1 }; +type Foo2 = { x: string } & { [K in number]: Foo2 };