Skip to content

Instantly share code, notes, and snippets.

@krisselden
Created April 13, 2017 02:09
Show Gist options
  • Save krisselden/6f1e8640a3edc4438672187f8ee9e878 to your computer and use it in GitHub Desktop.
Save krisselden/6f1e8640a3edc4438672187f8ee9e878 to your computer and use it in GitHub Desktop.
TypeScript documentation.
import * as ts from "typescript";
const options: ts.CompilerOptions = {
moduleResolution: ts.ModuleResolutionKind.NodeJs,
module: ts.ModuleKind.CommonJS,
target: ts.ScriptTarget.ES2015,
declaration: true
};
const host = ts.createCompilerHost(options);
const program = ts.createProgram(["index.ts"], options, host);
ts.getPreEmitDiagnostics(program);
const checker = program.getTypeChecker();
const entryFile = program.getSourceFile("index.ts");
const entrySymbol = checker.getSymbolAtLocation(entryFile);
const entryExports = checker.getExportsOfModule(entrySymbol);
entryExports.forEach(symbol => {
if (symbol.getFlags() & ts.SymbolFlags.Alias) {
symbol = checker.getAliasedSymbol(symbol);
}
let type = checker.getDeclaredTypeOfSymbol(symbol);
console.log(symbol.getDocumentationComment());
console.log(checker.typeToString(type));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment