api-builder: deduce the type of a symbol from its initializer

This commit is contained in:
Peter Bacon Darwin 2015-11-13 12:25:42 +00:00
parent 229557dcb2
commit 21feaf499f
1 changed files with 8 additions and 0 deletions

View File

@ -372,6 +372,14 @@ module.exports = function readTypeScriptModules(tsParser, modules, getFileInfo,
var sourceFile = ts.getSourceFileOfNode(declaration);
if (declaration.type) {
return getType(sourceFile, declaration.type).trim();
} else if (declaration.initializer) {
// The symbol does not have a "type" but it is being initialized
// so we can deduce the type of from the initializer (mostly).
if (declaration.initializer.expression) {
return declaration.initializer.expression.text.trim();
} else {
return getType(sourceFile, declaration.initializer).trim();
}
}
}