Skip to content

Commit a868c59

Browse files
author
Andy Hanson
committed
In getDeclarationSpaces, treat a type alias as a SymbolFlags.Type, not a SymbolFlags.Value
1 parent a277664 commit a868c59

File tree

4 files changed

+108
-2
lines changed

4 files changed

+108
-2
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18802,6 +18802,7 @@ namespace ts {
1880218802
function getDeclarationSpaces(d: Declaration): SymbolFlags {
1880318803
switch (d.kind) {
1880418804
case SyntaxKind.InterfaceDeclaration:
18805+
case SyntaxKind.TypeAliasDeclaration:
1880518806
return SymbolFlags.ExportType;
1880618807
case SyntaxKind.ModuleDeclaration:
1880718808
return isAmbientModule(d) || getModuleInstanceState(d) !== ModuleInstanceState.NonInstantiated
@@ -18811,12 +18812,15 @@ namespace ts {
1881118812
case SyntaxKind.EnumDeclaration:
1881218813
return SymbolFlags.ExportType | SymbolFlags.ExportValue;
1881318814
case SyntaxKind.ImportEqualsDeclaration:
18814-
let result: SymbolFlags = 0;
18815+
let result = SymbolFlags.None;
1881518816
const target = resolveAlias(getSymbolOfNode(d));
1881618817
forEach(target.declarations, d => { result |= getDeclarationSpaces(d); });
1881718818
return result;
18818-
default:
18819+
case SyntaxKind.VariableDeclaration:
18820+
case SyntaxKind.BindingElement:
1881918821
return SymbolFlags.ExportValue;
18822+
default:
18823+
Debug.fail((ts as any).SyntaxKind[d.kind]);
1882018824
}
1882118825
}
1882218826
}
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)