DEV Community

ShiYi
ShiYi

Posted on

Typescript Compiler API:How to get absolute path to source file of import module using typescript compiler api

I try to get the path information as follows:

  const typeChecker = program.getTypeChecker()
  const importFileSymbol = typeChecker.getSymbolAtLocation(
    importDeclarationNode.moduleSpecifier
  );
  const path = importFileSymbol?.valueDeclaration?.path || '';

In this way, I can get the sourceFile object of the module source file, and get the absolute path of the module through the path…

Top comments (0)