mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 07:45:18 -06:00
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
This commit is contained in:
parent
09441107c1
commit
20471182fc
@ -2530,8 +2530,8 @@ namespace ts {
|
||||
: error(name, Diagnostics.Module_0_declares_1_locally_but_it_is_not_exported, moduleName, declarationName);
|
||||
|
||||
addRelatedInfo(diagnostic,
|
||||
createDiagnosticForNode(localSymbol.valueDeclaration, Diagnostics._0_is_declared_here, declarationName)
|
||||
);
|
||||
...map(localSymbol.declarations, (decl, index) =>
|
||||
createDiagnosticForNode(decl, index === 0 ? Diagnostics._0_is_declared_here : Diagnostics.and_here, declarationName)));
|
||||
}
|
||||
else {
|
||||
error(name, Diagnostics.Module_0_has_no_exported_member_1, moduleName, declarationName);
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
tests/cases/compiler/b.ts(1,10): error TS2459: Module '"./a"' declares 'Foo' locally, but it is not exported.
|
||||
|
||||
|
||||
==== tests/cases/compiler/a.ts (0 errors) ====
|
||||
export {}
|
||||
interface Foo {}
|
||||
|
||||
==== tests/cases/compiler/b.ts (1 errors) ====
|
||||
import { Foo } from './a';
|
||||
~~~
|
||||
!!! error TS2459: Module '"./a"' declares 'Foo' locally, but it is not exported.
|
||||
!!! related TS2728 tests/cases/compiler/a.ts:2:11: 'Foo' is declared here.
|
||||
|
||||
16
tests/baselines/reference/importNonExportedMember2.js
Normal file
16
tests/baselines/reference/importNonExportedMember2.js
Normal file
@ -0,0 +1,16 @@
|
||||
//// [tests/cases/compiler/importNonExportedMember2.ts] ////
|
||||
|
||||
//// [a.ts]
|
||||
export {}
|
||||
interface Foo {}
|
||||
|
||||
//// [b.ts]
|
||||
import { Foo } from './a';
|
||||
|
||||
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
//// [b.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
@ -0,0 +1,9 @@
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
export {}
|
||||
interface Foo {}
|
||||
>Foo : Symbol(Foo, Decl(a.ts, 0, 9))
|
||||
|
||||
=== tests/cases/compiler/b.ts ===
|
||||
import { Foo } from './a';
|
||||
>Foo : Symbol(Foo, Decl(b.ts, 0, 8))
|
||||
|
||||
8
tests/baselines/reference/importNonExportedMember2.types
Normal file
8
tests/baselines/reference/importNonExportedMember2.types
Normal file
@ -0,0 +1,8 @@
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
export {}
|
||||
No type information for this code.interface Foo {}
|
||||
No type information for this code.
|
||||
No type information for this code.=== tests/cases/compiler/b.ts ===
|
||||
import { Foo } from './a';
|
||||
>Foo : any
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
tests/cases/compiler/b.ts(1,10): error TS2459: Module '"./a"' declares 'Foo' locally, but it is not exported.
|
||||
|
||||
|
||||
==== tests/cases/compiler/a.ts (0 errors) ====
|
||||
export {}
|
||||
interface Foo {}
|
||||
interface Foo {}
|
||||
namespace Foo {}
|
||||
|
||||
==== tests/cases/compiler/b.ts (1 errors) ====
|
||||
import { Foo } from './a';
|
||||
~~~
|
||||
!!! error TS2459: Module '"./a"' declares 'Foo' locally, but it is not exported.
|
||||
!!! related TS2728 tests/cases/compiler/a.ts:2:11: 'Foo' is declared here.
|
||||
!!! related TS6204 tests/cases/compiler/a.ts:3:11: and here.
|
||||
!!! related TS6204 tests/cases/compiler/a.ts:4:11: and here.
|
||||
|
||||
18
tests/baselines/reference/importNonExportedMember3.js
Normal file
18
tests/baselines/reference/importNonExportedMember3.js
Normal file
@ -0,0 +1,18 @@
|
||||
//// [tests/cases/compiler/importNonExportedMember3.ts] ////
|
||||
|
||||
//// [a.ts]
|
||||
export {}
|
||||
interface Foo {}
|
||||
interface Foo {}
|
||||
namespace Foo {}
|
||||
|
||||
//// [b.ts]
|
||||
import { Foo } from './a';
|
||||
|
||||
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
//// [b.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
15
tests/baselines/reference/importNonExportedMember3.symbols
Normal file
15
tests/baselines/reference/importNonExportedMember3.symbols
Normal file
@ -0,0 +1,15 @@
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
export {}
|
||||
interface Foo {}
|
||||
>Foo : Symbol(Foo, Decl(a.ts, 0, 9), Decl(a.ts, 1, 16), Decl(a.ts, 2, 16))
|
||||
|
||||
interface Foo {}
|
||||
>Foo : Symbol(Foo, Decl(a.ts, 0, 9), Decl(a.ts, 1, 16), Decl(a.ts, 2, 16))
|
||||
|
||||
namespace Foo {}
|
||||
>Foo : Symbol(Foo, Decl(a.ts, 0, 9), Decl(a.ts, 1, 16), Decl(a.ts, 2, 16))
|
||||
|
||||
=== tests/cases/compiler/b.ts ===
|
||||
import { Foo } from './a';
|
||||
>Foo : Symbol(Foo, Decl(b.ts, 0, 8))
|
||||
|
||||
10
tests/baselines/reference/importNonExportedMember3.types
Normal file
10
tests/baselines/reference/importNonExportedMember3.types
Normal file
@ -0,0 +1,10 @@
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
export {}
|
||||
No type information for this code.interface Foo {}
|
||||
No type information for this code.interface Foo {}
|
||||
No type information for this code.namespace Foo {}
|
||||
No type information for this code.
|
||||
No type information for this code.=== tests/cases/compiler/b.ts ===
|
||||
import { Foo } from './a';
|
||||
>Foo : any
|
||||
|
||||
6
tests/cases/compiler/importNonExportedMember2.ts
Normal file
6
tests/cases/compiler/importNonExportedMember2.ts
Normal file
@ -0,0 +1,6 @@
|
||||
// @Filename: a.ts
|
||||
export {}
|
||||
interface Foo {}
|
||||
|
||||
// @Filename: b.ts
|
||||
import { Foo } from './a';
|
||||
8
tests/cases/compiler/importNonExportedMember3.ts
Normal file
8
tests/cases/compiler/importNonExportedMember3.ts
Normal file
@ -0,0 +1,8 @@
|
||||
// @Filename: a.ts
|
||||
export {}
|
||||
interface Foo {}
|
||||
interface Foo {}
|
||||
namespace Foo {}
|
||||
|
||||
// @Filename: b.ts
|
||||
import { Foo } from './a';
|
||||
Loading…
x
Reference in New Issue
Block a user