Merge pull request #4202 from Microsoft/fix4194

Fix #4194: emit type paramters in type alias declaration
This commit is contained in:
Mohamed Hegazy 2015-08-06 16:48:58 -07:00
commit 24aa58ebee
9 changed files with 85 additions and 0 deletions

View File

@ -750,14 +750,18 @@ namespace ts {
}
function writeTypeAliasDeclaration(node: TypeAliasDeclaration) {
let prevEnclosingDeclaration = enclosingDeclaration;
enclosingDeclaration = node;
emitJsDocComments(node);
emitModuleElementDeclarationFlags(node);
write("type ");
writeTextOfNode(currentSourceFile, node.name);
emitTypeParameters(node.typeParameters);
write(" = ");
emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.type, getTypeAliasDeclarationVisibilityError);
write(";");
writeLine();
enclosingDeclaration = prevEnclosingDeclaration;
function getTypeAliasDeclarationVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic {
return {

View File

@ -0,0 +1,14 @@
//// [typeAliasDeclarationEmit.ts]
export type callback<T> = () => T;
export type CallbackArray<T extends callback> = () => T;
//// [typeAliasDeclarationEmit.js]
define(["require", "exports"], function (require, exports) {
});
//// [typeAliasDeclarationEmit.d.ts]
export declare type callback<T> = () => T;
export declare type CallbackArray<T extends callback> = () => T;

View File

@ -0,0 +1,13 @@
=== tests/cases/compiler/typeAliasDeclarationEmit.ts ===
export type callback<T> = () => T;
>callback : Symbol(callback, Decl(typeAliasDeclarationEmit.ts, 0, 0))
>T : Symbol(T, Decl(typeAliasDeclarationEmit.ts, 1, 21))
>T : Symbol(T, Decl(typeAliasDeclarationEmit.ts, 1, 21))
export type CallbackArray<T extends callback> = () => T;
>CallbackArray : Symbol(CallbackArray, Decl(typeAliasDeclarationEmit.ts, 1, 34))
>T : Symbol(T, Decl(typeAliasDeclarationEmit.ts, 3, 26))
>callback : Symbol(callback, Decl(typeAliasDeclarationEmit.ts, 0, 0))
>T : Symbol(T, Decl(typeAliasDeclarationEmit.ts, 3, 26))

View File

@ -0,0 +1,13 @@
=== tests/cases/compiler/typeAliasDeclarationEmit.ts ===
export type callback<T> = () => T;
>callback : () => T
>T : T
>T : T
export type CallbackArray<T extends callback> = () => T;
>CallbackArray : () => T
>T : T
>callback : () => T
>T : T

View File

@ -0,0 +1,13 @@
//// [typeAliasDeclarationEmit2.ts]
export type A<a> = { value: a };
//// [typeAliasDeclarationEmit2.js]
define(["require", "exports"], function (require, exports) {
});
//// [typeAliasDeclarationEmit2.d.ts]
export declare type A<a> = {
value: a;
};

View File

@ -0,0 +1,8 @@
=== tests/cases/compiler/typeAliasDeclarationEmit2.ts ===
export type A<a> = { value: a };
>A : Symbol(A, Decl(typeAliasDeclarationEmit2.ts, 0, 0))
>a : Symbol(a, Decl(typeAliasDeclarationEmit2.ts, 1, 14))
>value : Symbol(value, Decl(typeAliasDeclarationEmit2.ts, 1, 20))
>a : Symbol(a, Decl(typeAliasDeclarationEmit2.ts, 1, 14))

View File

@ -0,0 +1,8 @@
=== tests/cases/compiler/typeAliasDeclarationEmit2.ts ===
export type A<a> = { value: a };
>A : { value: a; }
>a : a
>value : a
>a : a

View File

@ -0,0 +1,7 @@
// @target: ES5
// @module: AMD
// @declaration: true
export type callback<T> = () => T;
export type CallbackArray<T extends callback> = () => T;

View File

@ -0,0 +1,5 @@
// @target: ES5
// @module: AMD
// @declaration: true
export type A<a> = { value: a };