fix(dts generation): add support for type aliases

Closes #3952
This commit is contained in:
Igor Minar 2015-09-03 09:48:33 -07:00
parent ad3b9cf232
commit d78261695b
2 changed files with 9 additions and 0 deletions

View File

@ -107,6 +107,10 @@ DtsSerializer.prototype = {
this.declaration(buffer, ast); this.declaration(buffer, ast);
}, },
typeAlias: function(buffer, ast) {
buffer.push('type ', ast.name, ' = ', ast.returnType);
},
serializeExport: function(ast) { serializeExport: function(ast) {
var buffer = new Buffer(); var buffer = new Buffer();
buffer.push('\n'); buffer.push('\n');
@ -121,6 +125,7 @@ DtsSerializer.prototype = {
case 'enum': this.enum(buffer, ast); break; case 'enum': this.enum(buffer, ast); break;
case 'var': this.var(buffer, ast); break; case 'var': this.var(buffer, ast); break;
case 'const': this.const(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); default: throw new Error("unknown docType: " + ast.docType);
} }

View File

@ -205,6 +205,10 @@ module.exports = function readTypeScriptModules(tsParser, modules, getFileInfo,
exportSymbol.valueDeclaration.type.typeName.text; exportSymbol.valueDeclaration.type.typeName.text;
} }
if (exportDoc.docType === 'type-alias') {
exportDoc.returnType = getReturnType(typeChecker, exportSymbol);
}
if(exportSymbol.flags & ts.SymbolFlags.Function) { if(exportSymbol.flags & ts.SymbolFlags.Function) {
exportDoc.parameters = getParameters(typeChecker, exportSymbol); exportDoc.parameters = getParameters(typeChecker, exportSymbol);
} }