Basic example:
const fileNames = ["C:\\MyFile.ts"];
const compilerOptions: ts.CompilerOptions = {
// specify compiler options here if needed...
// refer to ts.CompilerOptions for available settings
};
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());
}
});
});
For instance, providing it with a C:\MyFile.ts
that contains:
class MyClass {}
interface MyInterface {}
The output would be MyClass
and MyInterface
.
Exploring beyond this demonstration requires significant effort. You may find it more helpful to explore or contribute to this ongoing project.