Refer to: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API, I want to get type of node in AST.
It is successful for angular project because it is written using typescript and tsconfig.json exists.
When I try to analyze react app which is written using javascript
const program = ts.createProgram({
rootNames: [fileName],
options: {
strict: true,
target: ts.ScriptTarget.ES2015,
allowJs: true,
checkJs: true
}
})
const typeChecker = program.getTypeChecker();
... ...
I get: typechecker.getTypeAtLocation(node).getSymbol() is undefined.
I assume options of ts.createProgram is wrong.
typeChecker.getTypeAtLocation(node)might be returning theerrortype. Are there any diagnostics returned byts.getPreEmitDiagnostics(program)?