From d78261695b3db304501063e69f600252d5e6f445 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Thu, 3 Sep 2015 09:48:33 -0700 Subject: [PATCH] fix(dts generation): add support for type aliases Closes #3952 --- docs/typescript-definition-package/processors/code_gen.js | 5 +++++ docs/typescript-package/processors/readTypeScriptModules.js | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/docs/typescript-definition-package/processors/code_gen.js b/docs/typescript-definition-package/processors/code_gen.js index 1f8103cb7d..04136e4d69 100644 --- a/docs/typescript-definition-package/processors/code_gen.js +++ b/docs/typescript-definition-package/processors/code_gen.js @@ -107,6 +107,10 @@ DtsSerializer.prototype = { this.declaration(buffer, ast); }, + typeAlias: function(buffer, ast) { + buffer.push('type ', ast.name, ' = ', ast.returnType); + }, + serializeExport: function(ast) { var buffer = new Buffer(); buffer.push('\n'); @@ -121,6 +125,7 @@ DtsSerializer.prototype = { case 'enum': this.enum(buffer, ast); break; case 'var': this.var(buffer, ast); break; case 'const': this.const(buffer, ast); break; + case 'type-alias': this.typeAlias(buffer, ast); break; default: throw new Error("unknown docType: " + ast.docType); } diff --git a/docs/typescript-package/processors/readTypeScriptModules.js b/docs/typescript-package/processors/readTypeScriptModules.js index 7d314c9f07..f0cfc87036 100644 --- a/docs/typescript-package/processors/readTypeScriptModules.js +++ b/docs/typescript-package/processors/readTypeScriptModules.js @@ -205,6 +205,10 @@ module.exports = function readTypeScriptModules(tsParser, modules, getFileInfo, exportSymbol.valueDeclaration.type.typeName.text; } + if (exportDoc.docType === 'type-alias') { + exportDoc.returnType = getReturnType(typeChecker, exportSymbol); + } + if(exportSymbol.flags & ts.SymbolFlags.Function) { exportDoc.parameters = getParameters(typeChecker, exportSymbol); }