diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 645bf049f4e12..b2729662e9500 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10398,7 +10398,10 @@ namespace ts { return symbol; } } - return getPropertyOfObjectType(globalObjectType, name); + if (globalObjectType) { + return getPropertyOfObjectType(globalObjectType, name); + } + return undefined; } if (type.flags & TypeFlags.UnionOrIntersection) { return getPropertyOfUnionOrIntersectionType(type, name); diff --git a/tests/baselines/reference/importNonExistentDeclaration.errors.txt b/tests/baselines/reference/importNonExistentDeclaration.errors.txt new file mode 100644 index 0000000000000..435bdbabea43e --- /dev/null +++ b/tests/baselines/reference/importNonExistentDeclaration.errors.txt @@ -0,0 +1,22 @@ +tests/cases/compiler/bar.d.ts(1,10): error TS2305: Module '"./foo"' has no exported member 'Bar'. + + +==== tests/cases/compiler/foo.d.ts (0 errors) ==== + export = Foo; + export as namespace Foo; + + declare namespace Foo { + function foo(); + } + + declare global { + namespace Bar {} + } + +==== tests/cases/compiler/bar.d.ts (1 errors) ==== + import { Bar } from './foo'; + ~~~ +!!! error TS2305: Module '"./foo"' has no exported member 'Bar'. + export = Bar; + export as namespace Bar; + \ No newline at end of file diff --git a/tests/baselines/reference/importNonExistentDeclaration.symbols b/tests/baselines/reference/importNonExistentDeclaration.symbols new file mode 100644 index 0000000000000..ef7a3f9c70795 --- /dev/null +++ b/tests/baselines/reference/importNonExistentDeclaration.symbols @@ -0,0 +1,31 @@ +=== tests/cases/compiler/foo.d.ts === +export = Foo; +>Foo : Symbol(Foo, Decl(foo.d.ts, 1, 24)) + +export as namespace Foo; +>Foo : Symbol(Foo, Decl(foo.d.ts, 0, 13)) + +declare namespace Foo { +>Foo : Symbol(Foo, Decl(foo.d.ts, 1, 24)) + + function foo(); +>foo : Symbol(foo, Decl(foo.d.ts, 3, 23)) +} + +declare global { +>global : Symbol(global, Decl(foo.d.ts, 5, 1)) + + namespace Bar {} +>Bar : Symbol(Bar, Decl(foo.d.ts, 7, 16)) +} + +=== tests/cases/compiler/bar.d.ts === +import { Bar } from './foo'; +>Bar : Symbol(Bar, Decl(bar.d.ts, 0, 8)) + +export = Bar; +>Bar : Symbol(Bar, Decl(bar.d.ts, 0, 8)) + +export as namespace Bar; +>Bar : Symbol(Bar, Decl(bar.d.ts, 1, 13)) + diff --git a/tests/baselines/reference/importNonExistentDeclaration.types b/tests/baselines/reference/importNonExistentDeclaration.types new file mode 100644 index 0000000000000..d2bece5dc092b --- /dev/null +++ b/tests/baselines/reference/importNonExistentDeclaration.types @@ -0,0 +1,30 @@ +=== tests/cases/compiler/foo.d.ts === +export = Foo; +>Foo : typeof Foo + +export as namespace Foo; +>Foo : typeof Foo + +declare namespace Foo { +>Foo : typeof Foo + + function foo(); +>foo : () => any +} + +declare global { +>global : any + + namespace Bar {} +} + +=== tests/cases/compiler/bar.d.ts === +import { Bar } from './foo'; +>Bar : any + +export = Bar; +>Bar : any + +export as namespace Bar; +>Bar : any + diff --git a/tests/cases/compiler/importNonExistentDeclaration.ts b/tests/cases/compiler/importNonExistentDeclaration.ts new file mode 100644 index 0000000000000..259b507c7c2c2 --- /dev/null +++ b/tests/cases/compiler/importNonExistentDeclaration.ts @@ -0,0 +1,16 @@ +// @filename: foo.d.ts +export = Foo; +export as namespace Foo; + +declare namespace Foo { + function foo(); +} + +declare global { + namespace Bar {} +} + +// @filename: bar.d.ts +import { Bar } from './foo'; +export = Bar; +export as namespace Bar;