diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1eb750c8939ba..db696ac2c6283 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9703,7 +9703,7 @@ namespace ts { // fill in any as-yet-unresolved late-bound members. const lateSymbols = createSymbolTable() as UnderscoreEscapedMap; - for (const decl of symbol.declarations) { + for (const decl of symbol.declarations || emptyArray) { const members = getMembersOfDeclaration(decl); if (members) { for (const member of members) { diff --git a/tests/baselines/reference/intersectionsAndEmptyObjects.js b/tests/baselines/reference/intersectionsAndEmptyObjects.js index 4ff24248f4690..d1abeb2215251 100644 --- a/tests/baselines/reference/intersectionsAndEmptyObjects.js +++ b/tests/baselines/reference/intersectionsAndEmptyObjects.js @@ -1,3 +1,5 @@ +//// [tests/cases/conformance/types/intersection/intersectionsAndEmptyObjects.ts] //// + //// [intersectionsAndEmptyObjects.ts] // Empty object type literals are removed from intersections types // that contain other object types @@ -80,11 +82,38 @@ var unknownChoicesAndEmpty: choices; type Foo1 = { x: string } & { [x: number]: Foo1 }; type Foo2 = { x: string } & { [K in number]: Foo2 }; + +// Repro from #40239 + +declare function mock(_: Promise): {} & M; +mock(import('./ex')) + +//// [ex.d.ts] +export {} //// [intersectionsAndEmptyObjects.js] // Empty object type literals are removed from intersections types // that contain other object types +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; let x01; let x02; let x03; @@ -121,3 +150,4 @@ var myChoices; var myChoicesAndEmpty; var unknownChoices; var unknownChoicesAndEmpty; +mock(Promise.resolve().then(() => __importStar(require('./ex')))); diff --git a/tests/baselines/reference/intersectionsAndEmptyObjects.symbols b/tests/baselines/reference/intersectionsAndEmptyObjects.symbols index 39131564a5950..7cb08ebfb2523 100644 --- a/tests/baselines/reference/intersectionsAndEmptyObjects.symbols +++ b/tests/baselines/reference/intersectionsAndEmptyObjects.symbols @@ -260,3 +260,21 @@ type Foo2 = { x: string } & { [K in number]: Foo2 }; >K : Symbol(K, Decl(intersectionsAndEmptyObjects.ts, 80, 31)) >Foo2 : Symbol(Foo2, Decl(intersectionsAndEmptyObjects.ts, 79, 50)) +// Repro from #40239 + +declare function mock(_: Promise): {} & M; +>mock : Symbol(mock, Decl(intersectionsAndEmptyObjects.ts, 80, 52)) +>M : Symbol(M, Decl(intersectionsAndEmptyObjects.ts, 84, 22)) +>_ : Symbol(_, Decl(intersectionsAndEmptyObjects.ts, 84, 25)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>M : Symbol(M, Decl(intersectionsAndEmptyObjects.ts, 84, 22)) +>M : Symbol(M, Decl(intersectionsAndEmptyObjects.ts, 84, 22)) + +mock(import('./ex')) +>mock : Symbol(mock, Decl(intersectionsAndEmptyObjects.ts, 80, 52)) +>'./ex' : Symbol("tests/cases/conformance/types/intersection/ex", Decl(ex.d.ts, 0, 0)) + +=== tests/cases/conformance/types/intersection/ex.d.ts === +export {} +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/intersectionsAndEmptyObjects.types b/tests/baselines/reference/intersectionsAndEmptyObjects.types index 889ee33d378a2..423882a14f388 100644 --- a/tests/baselines/reference/intersectionsAndEmptyObjects.types +++ b/tests/baselines/reference/intersectionsAndEmptyObjects.types @@ -217,3 +217,19 @@ type Foo2 = { x: string } & { [K in number]: Foo2 }; >Foo2 : Foo2 >x : string +// Repro from #40239 + +declare function mock(_: Promise): {} & M; +>mock : (_: Promise) => {} & M +>_ : Promise + +mock(import('./ex')) +>mock(import('./ex')) : {} +>mock : (_: Promise) => {} & M +>import('./ex') : Promise<{ default: typeof import("tests/cases/conformance/types/intersection/ex"); }> +>'./ex' : "./ex" + +=== tests/cases/conformance/types/intersection/ex.d.ts === +export {} +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/cases/conformance/types/intersection/intersectionsAndEmptyObjects.ts b/tests/cases/conformance/types/intersection/intersectionsAndEmptyObjects.ts index 00db917b96702..a2657fab4ba30 100644 --- a/tests/cases/conformance/types/intersection/intersectionsAndEmptyObjects.ts +++ b/tests/cases/conformance/types/intersection/intersectionsAndEmptyObjects.ts @@ -1,4 +1,7 @@ // @target: es2015 +// @module: commonjs +// @esModuleInterop: true +// @filename: intersectionsAndEmptyObjects.ts // Empty object type literals are removed from intersections types // that contain other object types @@ -81,3 +84,11 @@ var unknownChoicesAndEmpty: choices; type Foo1 = { x: string } & { [x: number]: Foo1 }; type Foo2 = { x: string } & { [K in number]: Foo2 }; + +// Repro from #40239 + +declare function mock(_: Promise): {} & M; +mock(import('./ex')) + +// @filename: ex.d.ts +export {}