Skip to content

Commit e13d6fa

Browse files
committed
Merge pull request #1760 from Microsoft/typeAliasDoesntMakeModuleInstantiated
Type alias declaration is type only declaration and doesnt make module instantiated
2 parents 8f36090 + 4d11824 commit e13d6fa

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

src/compiler/binder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ module ts {
99

1010
export function getModuleInstanceState(node: Node): ModuleInstanceState {
1111
// A module is uninstantiated if it contains only
12-
// 1. interface declarations
13-
if (node.kind === SyntaxKind.InterfaceDeclaration) {
12+
// 1. interface declarations, type alias declarations
13+
if (node.kind === SyntaxKind.InterfaceDeclaration || node.kind === SyntaxKind.TypeAliasDeclaration) {
1414
return ModuleInstanceState.NonInstantiated;
1515
}
1616
// 2. const enum declarations don't make module instantiated
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//// [typeAliasDoesntMakeModuleInstantiated.ts]
2+
declare module m {
3+
// type alias declaration here shouldnt make the module declaration instantiated
4+
type Selector = string| string[] |Function;
5+
6+
export interface IStatic {
7+
(selector: any /* Selector */): IInstance;
8+
}
9+
export interface IInstance { }
10+
}
11+
declare var m: m.IStatic; // Should be ok to have var 'm' as module is non instantiated
12+
13+
//// [typeAliasDoesntMakeModuleInstantiated.js]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
=== tests/cases/compiler/typeAliasDoesntMakeModuleInstantiated.ts ===
2+
declare module m {
3+
>m : IStatic
4+
5+
// type alias declaration here shouldnt make the module declaration instantiated
6+
type Selector = string| string[] |Function;
7+
>Selector : string | Function | string[]
8+
>Function : Function
9+
10+
export interface IStatic {
11+
>IStatic : IStatic
12+
13+
(selector: any /* Selector */): IInstance;
14+
>selector : any
15+
>IInstance : IInstance
16+
}
17+
export interface IInstance { }
18+
>IInstance : IInstance
19+
}
20+
declare var m: m.IStatic; // Should be ok to have var 'm' as module is non instantiated
21+
>m : m.IStatic
22+
>m : unknown
23+
>IStatic : m.IStatic
24+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
declare module m {
2+
// type alias declaration here shouldnt make the module declaration instantiated
3+
type Selector = string| string[] |Function;
4+
5+
export interface IStatic {
6+
(selector: any /* Selector */): IInstance;
7+
}
8+
export interface IInstance { }
9+
}
10+
declare var m: m.IStatic; // Should be ok to have var 'm' as module is non instantiated

0 commit comments

Comments
 (0)