api-builder: deduce the type of a symbol from its initializer
This commit is contained in:
parent
229557dcb2
commit
21feaf499f
|
@ -372,6 +372,14 @@ module.exports = function readTypeScriptModules(tsParser, modules, getFileInfo,
|
||||||
var sourceFile = ts.getSourceFileOfNode(declaration);
|
var sourceFile = ts.getSourceFileOfNode(declaration);
|
||||||
if (declaration.type) {
|
if (declaration.type) {
|
||||||
return getType(sourceFile, declaration.type).trim();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue