It's because ts.Type and ts.TypeNode doesn't have a symbol, so they can't call getSourceFile() function.
// get the source file of a type alias declaration
function findTypeDeclarationSourceFile(type: ts.TypeNode, checker: ts.TypeChecker): string | undefined {
const symbol = checker.getSymbolAtLocation(type); // return undefined
if (symbol) {
const declarations = symbol.getDeclarations();
if (declarations) {
const declaration = declarations[0];
const sourceFile = declaration.getSourceFile();
if (sourceFile) {
return sourceFile.fileName;
}
}
}
return undefined;
}
Is there other ways I can get source file information from ts.TypeNode or ts.Type?
The goal is to generate
So wee need to know
vega-lite/src/spec/toplevel
is the source file of typeAutosizeType
andAutoSizeParams
.Refers to https://stackoverflow.com/questions/58653091/typescript-compiler-api-find-which-file-a-type-came-from, I can get the source file of the AST nodes(code), but I can't get such information from
ts.Type
orts.TypeNode
(code).It's because
ts.Type
andts.TypeNode
doesn't have a symbol, so they can't callgetSourceFile()
function.Is there other ways I can get source file information from ts.TypeNode or ts.Type?