Skip to content

Commit f45ccf5

Browse files
author
Andy
authored
In getDeclarationSpaces, treat a type alias as a SymbolFlags.Type, not a SymbolFlags.Value (microsoft#16624)
1 parent 1408109 commit f45ccf5

File tree

4 files changed

+110
-2
lines changed

4 files changed

+110
-2
lines changed

src/compiler/checker.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18860,6 +18860,7 @@ namespace ts {
1886018860
function getDeclarationSpaces(d: Declaration): SymbolFlags {
1886118861
switch (d.kind) {
1886218862
case SyntaxKind.InterfaceDeclaration:
18863+
case SyntaxKind.TypeAliasDeclaration:
1886318864
return SymbolFlags.ExportType;
1886418865
case SyntaxKind.ModuleDeclaration:
1886518866
return isAmbientModule(d) || getModuleInstanceState(d) !== ModuleInstanceState.NonInstantiated
@@ -18869,12 +18870,17 @@ namespace ts {
1886918870
case SyntaxKind.EnumDeclaration:
1887018871
return SymbolFlags.ExportType | SymbolFlags.ExportValue;
1887118872
case SyntaxKind.ImportEqualsDeclaration:
18872-
let result: SymbolFlags = 0;
18873+
let result = SymbolFlags.None;
1887318874
const target = resolveAlias(getSymbolOfNode(d));
1887418875
forEach(target.declarations, d => { result |= getDeclarationSpaces(d); });
1887518876
return result;
18876-
default:
18877+
case SyntaxKind.VariableDeclaration:
18878+
case SyntaxKind.BindingElement:
18879+
case SyntaxKind.FunctionDeclaration:
18880+
case SyntaxKind.ImportSpecifier: // https://github.com/Microsoft/TypeScript/pull/7591
1887718881
return SymbolFlags.ExportValue;
18882+
default:
18883+
Debug.fail((ts as any).SyntaxKind[d.kind]);
1887818884
}
1887918885
}
1888018886
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
tests/cases/compiler/mergedDeclarationExports.ts(13,11): error TS2395: Individual declarations in merged declaration 'c' must be all exported or all local.
2+
tests/cases/compiler/mergedDeclarationExports.ts(14,18): error TS2395: Individual declarations in merged declaration 'c' must be all exported or all local.
3+
tests/cases/compiler/mergedDeclarationExports.ts(17,11): error TS2395: Individual declarations in merged declaration 'd' must be all exported or all local.
4+
tests/cases/compiler/mergedDeclarationExports.ts(18,14): error TS2395: Individual declarations in merged declaration 'd' must be all exported or all local.
5+
tests/cases/compiler/mergedDeclarationExports.ts(21,11): error TS2395: Individual declarations in merged declaration 'N' must be all exported or all local.
6+
tests/cases/compiler/mergedDeclarationExports.ts(22,18): error TS2395: Individual declarations in merged declaration 'N' must be all exported or all local.
7+
8+
9+
==== tests/cases/compiler/mergedDeclarationExports.ts (6 errors) ====
10+
// OK -- one is type, one is value
11+
interface b {}
12+
export const b = 1;
13+
14+
// OK -- one is a type, one is a namespace, one is a value.
15+
type t = 0;
16+
namespace t { interface I {} }
17+
export const t = 0;
18+
19+
// Should get errors if they have some meaning in common.
20+
21+
// both types
22+
interface c {}
23+
~
24+
!!! error TS2395: Individual declarations in merged declaration 'c' must be all exported or all local.
25+
export interface c {}
26+
~
27+
!!! error TS2395: Individual declarations in merged declaration 'c' must be all exported or all local.
28+
29+
// both types (class is also value, but that doesn't matter)
30+
interface d {}
31+
~
32+
!!! error TS2395: Individual declarations in merged declaration 'd' must be all exported or all local.
33+
export class d {}
34+
~
35+
!!! error TS2395: Individual declarations in merged declaration 'd' must be all exported or all local.
36+
37+
// both namespaces
38+
namespace N { }
39+
~
40+
!!! error TS2395: Individual declarations in merged declaration 'N' must be all exported or all local.
41+
export namespace N {}
42+
~
43+
!!! error TS2395: Individual declarations in merged declaration 'N' must be all exported or all local.
44+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//// [mergedDeclarationExports.ts]
2+
// OK -- one is type, one is value
3+
interface b {}
4+
export const b = 1;
5+
6+
// OK -- one is a type, one is a namespace, one is a value.
7+
type t = 0;
8+
namespace t { interface I {} }
9+
export const t = 0;
10+
11+
// Should get errors if they have some meaning in common.
12+
13+
// both types
14+
interface c {}
15+
export interface c {}
16+
17+
// both types (class is also value, but that doesn't matter)
18+
interface d {}
19+
export class d {}
20+
21+
// both namespaces
22+
namespace N { }
23+
export namespace N {}
24+
25+
26+
//// [mergedDeclarationExports.js]
27+
"use strict";
28+
exports.__esModule = true;
29+
exports.b = 1;
30+
exports.t = 0;
31+
var d = (function () {
32+
function d() {
33+
}
34+
return d;
35+
}());
36+
exports.d = d;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// OK -- one is type, one is value
2+
interface b {}
3+
export const b = 1;
4+
5+
// OK -- one is a type, one is a namespace, one is a value.
6+
type t = 0;
7+
namespace t { interface I {} }
8+
export const t = 0;
9+
10+
// Should get errors if they have some meaning in common.
11+
12+
// both types
13+
interface c {}
14+
export interface c {}
15+
16+
// both types (class is also value, but that doesn't matter)
17+
interface d {}
18+
export class d {}
19+
20+
// both namespaces
21+
namespace N { }
22+
export namespace N {}

0 commit comments

Comments
 (0)