Skip to content

Commit 24aa58e

Browse files
committed
Merge pull request microsoft#4202 from Microsoft/fix4194
Fix microsoft#4194: emit type paramters in type alias declaration
2 parents bb4aa2c + d58ec43 commit 24aa58e

9 files changed

+85
-0
lines changed

src/compiler/declarationEmitter.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,14 +750,18 @@ namespace ts {
750750
}
751751

752752
function writeTypeAliasDeclaration(node: TypeAliasDeclaration) {
753+
let prevEnclosingDeclaration = enclosingDeclaration;
754+
enclosingDeclaration = node;
753755
emitJsDocComments(node);
754756
emitModuleElementDeclarationFlags(node);
755757
write("type ");
756758
writeTextOfNode(currentSourceFile, node.name);
759+
emitTypeParameters(node.typeParameters);
757760
write(" = ");
758761
emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.type, getTypeAliasDeclarationVisibilityError);
759762
write(";");
760763
writeLine();
764+
enclosingDeclaration = prevEnclosingDeclaration;
761765

762766
function getTypeAliasDeclarationVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic {
763767
return {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//// [typeAliasDeclarationEmit.ts]
2+
3+
export type callback<T> = () => T;
4+
5+
export type CallbackArray<T extends callback> = () => T;
6+
7+
//// [typeAliasDeclarationEmit.js]
8+
define(["require", "exports"], function (require, exports) {
9+
});
10+
11+
12+
//// [typeAliasDeclarationEmit.d.ts]
13+
export declare type callback<T> = () => T;
14+
export declare type CallbackArray<T extends callback> = () => T;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/compiler/typeAliasDeclarationEmit.ts ===
2+
3+
export type callback<T> = () => T;
4+
>callback : Symbol(callback, Decl(typeAliasDeclarationEmit.ts, 0, 0))
5+
>T : Symbol(T, Decl(typeAliasDeclarationEmit.ts, 1, 21))
6+
>T : Symbol(T, Decl(typeAliasDeclarationEmit.ts, 1, 21))
7+
8+
export type CallbackArray<T extends callback> = () => T;
9+
>CallbackArray : Symbol(CallbackArray, Decl(typeAliasDeclarationEmit.ts, 1, 34))
10+
>T : Symbol(T, Decl(typeAliasDeclarationEmit.ts, 3, 26))
11+
>callback : Symbol(callback, Decl(typeAliasDeclarationEmit.ts, 0, 0))
12+
>T : Symbol(T, Decl(typeAliasDeclarationEmit.ts, 3, 26))
13+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/compiler/typeAliasDeclarationEmit.ts ===
2+
3+
export type callback<T> = () => T;
4+
>callback : () => T
5+
>T : T
6+
>T : T
7+
8+
export type CallbackArray<T extends callback> = () => T;
9+
>CallbackArray : () => T
10+
>T : T
11+
>callback : () => T
12+
>T : T
13+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//// [typeAliasDeclarationEmit2.ts]
2+
3+
export type A<a> = { value: a };
4+
5+
//// [typeAliasDeclarationEmit2.js]
6+
define(["require", "exports"], function (require, exports) {
7+
});
8+
9+
10+
//// [typeAliasDeclarationEmit2.d.ts]
11+
export declare type A<a> = {
12+
value: a;
13+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/compiler/typeAliasDeclarationEmit2.ts ===
2+
3+
export type A<a> = { value: a };
4+
>A : Symbol(A, Decl(typeAliasDeclarationEmit2.ts, 0, 0))
5+
>a : Symbol(a, Decl(typeAliasDeclarationEmit2.ts, 1, 14))
6+
>value : Symbol(value, Decl(typeAliasDeclarationEmit2.ts, 1, 20))
7+
>a : Symbol(a, Decl(typeAliasDeclarationEmit2.ts, 1, 14))
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/compiler/typeAliasDeclarationEmit2.ts ===
2+
3+
export type A<a> = { value: a };
4+
>A : { value: a; }
5+
>a : a
6+
>value : a
7+
>a : a
8+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @target: ES5
2+
// @module: AMD
3+
// @declaration: true
4+
5+
export type callback<T> = () => T;
6+
7+
export type CallbackArray<T extends callback> = () => T;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @target: ES5
2+
// @module: AMD
3+
// @declaration: true
4+
5+
export type A<a> = { value: a };

0 commit comments

Comments
 (0)