【发布时间】:2021-10-09 11:40:26
【问题描述】:
// sourceFileContent
import path from 'path';
// Short version of node_modules/@types/node/path.d.ts
declare module 'path' {
namespace path {
interface ParsedPath {}
interface FormatInputPathObject {}
interface PlatformPath {
normalize(p: string): string;
join(...paths: string[]): string;
// other...
}
}
const path: path.PlatformPath;
export = path;
}
下面的代码是使用 ts-morph 编写的,它是 typescript 的包装器
const sourceFile = project.createSourceFile('source.ts', sourceFileContent);
const importDeclarations = sourceFile.getImportDeclarations();
// loop for importDeclarations
let symbol = importDeclaration.getImportClause().getSymbol();
symbol = typeChecker.getAliasedSymbol(symbol);
const exportSymbols = typeChecker.getExportsOfModule(symbol);
// {"ParsedPath" => SymbolObject, "FormatInputPathObject" => SymbolObject, "PlatformPath" => SymbolObject}
这里我得到了三个导出符号,但是我们知道normalize、join 和其他应该存在于path 模块中的函数。
import { normalize, join } from 'path'; // no errors
所以我一直在获取这些功能(normalize、join 等),你能帮忙吗
使用 ts-morph 或裸 typescript API 从模块中获取所有可能的导出?
【问题讨论】:
标签: typescript typescript-compiler-api