From 21feaf499f265d19f6f19f96761234c85374bdbc Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Fri, 13 Nov 2015 12:25:42 +0000 Subject: [PATCH] api-builder: deduce the type of a symbol from its initializer --- .../processors/readTypeScriptModules.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/api-builder/typescript-package/processors/readTypeScriptModules.js b/tools/api-builder/typescript-package/processors/readTypeScriptModules.js index e9eeef74db..2445546a28 100644 --- a/tools/api-builder/typescript-package/processors/readTypeScriptModules.js +++ b/tools/api-builder/typescript-package/processors/readTypeScriptModules.js @@ -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(); + } } }