Created
April 13, 2017 02:09
-
-
Save krisselden/6f1e8640a3edc4438672187f8ee9e878 to your computer and use it in GitHub Desktop.
TypeScript documentation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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