Skip to content

Commit 2047118

Browse files
authored
Fix crash when trying to import a non-exported type (#36619)
* Fix crash when trying to import a non-exported type * Add related info on each declaration
1 parent 0944110 commit 2047118

11 files changed

+122
-2
lines changed

src/compiler/checker.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2530,8 +2530,8 @@ namespace ts {
25302530
: error(name, Diagnostics.Module_0_declares_1_locally_but_it_is_not_exported, moduleName, declarationName);
25312531

25322532
addRelatedInfo(diagnostic,
2533-
createDiagnosticForNode(localSymbol.valueDeclaration, Diagnostics._0_is_declared_here, declarationName)
2534-
);
2533+
...map(localSymbol.declarations, (decl, index) =>
2534+
createDiagnosticForNode(decl, index === 0 ? Diagnostics._0_is_declared_here : Diagnostics.and_here, declarationName)));
25352535
}
25362536
else {
25372537
error(name, Diagnostics.Module_0_has_no_exported_member_1, moduleName, declarationName);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
tests/cases/compiler/b.ts(1,10): error TS2459: Module '"./a"' declares 'Foo' locally, but it is not exported.
2+
3+
4+
==== tests/cases/compiler/a.ts (0 errors) ====
5+
export {}
6+
interface Foo {}
7+
8+
==== tests/cases/compiler/b.ts (1 errors) ====
9+
import { Foo } from './a';
10+
~~~
11+
!!! error TS2459: Module '"./a"' declares 'Foo' locally, but it is not exported.
12+
!!! related TS2728 tests/cases/compiler/a.ts:2:11: 'Foo' is declared here.
13+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//// [tests/cases/compiler/importNonExportedMember2.ts] ////
2+
3+
//// [a.ts]
4+
export {}
5+
interface Foo {}
6+
7+
//// [b.ts]
8+
import { Foo } from './a';
9+
10+
11+
//// [a.js]
12+
"use strict";
13+
exports.__esModule = true;
14+
//// [b.js]
15+
"use strict";
16+
exports.__esModule = true;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
=== tests/cases/compiler/a.ts ===
2+
export {}
3+
interface Foo {}
4+
>Foo : Symbol(Foo, Decl(a.ts, 0, 9))
5+
6+
=== tests/cases/compiler/b.ts ===
7+
import { Foo } from './a';
8+
>Foo : Symbol(Foo, Decl(b.ts, 0, 8))
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/compiler/a.ts ===
2+
export {}
3+
No type information for this code.interface Foo {}
4+
No type information for this code.
5+
No type information for this code.=== tests/cases/compiler/b.ts ===
6+
import { Foo } from './a';
7+
>Foo : any
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
tests/cases/compiler/b.ts(1,10): error TS2459: Module '"./a"' declares 'Foo' locally, but it is not exported.
2+
3+
4+
==== tests/cases/compiler/a.ts (0 errors) ====
5+
export {}
6+
interface Foo {}
7+
interface Foo {}
8+
namespace Foo {}
9+
10+
==== tests/cases/compiler/b.ts (1 errors) ====
11+
import { Foo } from './a';
12+
~~~
13+
!!! error TS2459: Module '"./a"' declares 'Foo' locally, but it is not exported.
14+
!!! related TS2728 tests/cases/compiler/a.ts:2:11: 'Foo' is declared here.
15+
!!! related TS6204 tests/cases/compiler/a.ts:3:11: and here.
16+
!!! related TS6204 tests/cases/compiler/a.ts:4:11: and here.
17+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//// [tests/cases/compiler/importNonExportedMember3.ts] ////
2+
3+
//// [a.ts]
4+
export {}
5+
interface Foo {}
6+
interface Foo {}
7+
namespace Foo {}
8+
9+
//// [b.ts]
10+
import { Foo } from './a';
11+
12+
13+
//// [a.js]
14+
"use strict";
15+
exports.__esModule = true;
16+
//// [b.js]
17+
"use strict";
18+
exports.__esModule = true;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
=== tests/cases/compiler/a.ts ===
2+
export {}
3+
interface Foo {}
4+
>Foo : Symbol(Foo, Decl(a.ts, 0, 9), Decl(a.ts, 1, 16), Decl(a.ts, 2, 16))
5+
6+
interface Foo {}
7+
>Foo : Symbol(Foo, Decl(a.ts, 0, 9), Decl(a.ts, 1, 16), Decl(a.ts, 2, 16))
8+
9+
namespace Foo {}
10+
>Foo : Symbol(Foo, Decl(a.ts, 0, 9), Decl(a.ts, 1, 16), Decl(a.ts, 2, 16))
11+
12+
=== tests/cases/compiler/b.ts ===
13+
import { Foo } from './a';
14+
>Foo : Symbol(Foo, Decl(b.ts, 0, 8))
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== tests/cases/compiler/a.ts ===
2+
export {}
3+
No type information for this code.interface Foo {}
4+
No type information for this code.interface Foo {}
5+
No type information for this code.namespace Foo {}
6+
No type information for this code.
7+
No type information for this code.=== tests/cases/compiler/b.ts ===
8+
import { Foo } from './a';
9+
>Foo : any
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// @Filename: a.ts
2+
export {}
3+
interface Foo {}
4+
5+
// @Filename: b.ts
6+
import { Foo } from './a';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @Filename: a.ts
2+
export {}
3+
interface Foo {}
4+
interface Foo {}
5+
namespace Foo {}
6+
7+
// @Filename: b.ts
8+
import { Foo } from './a';

0 commit comments

Comments
 (0)