Basicコード:あなたが提供するのであれば
const fileNames = ["C:\\MyFile.ts"];
const compilerOptions: ts.CompilerOptions = {
// compiler options go here if any...
// look at ts.CompilerOptions to see what's available
};
const program = ts.createProgram(fileNames, compilerOptions);
const typeChecker = program.getTypeChecker();
const sourceFiles = program.getSourceFiles();
sourceFiles.filter(f => /MyFile\.ts$/.test(f.fileName)).forEach(sourceFile => {
ts.forEachChild(sourceFile, node => {
const declaration = node as ts.Declaration;
if (declaration.name) {
console.log(declaration.name.getText());
}
});
});
ものとC:\MyFile.ts
よう:
class MyClass {}
interface MyInterface {}
それは出力MyClass
とMyInterface
だろう。
私がちょうど示したものを超えてすべてを理解することは、多くの仕事です。 this work in progressに目を通したり貢献したりすることがより有益な場合があります。
{/ *コンパイラのオプションはここにあります* /}は分かりませんでした。その意味は何ですか? –
@AhmedRaza tsconfig.jsonにあるようなコンパイラオプション。型は 'ts.CompilerOptions'になります。私は私の答えを更新します。 –
それに関連するすべての例を共有してください。 –