Fabio Spampinato
Fabio Spampinato

Reputation: 717

How do I check if a file path, or its content as a string, have any type errors?

As per the title, I need a way of knowing if a specific file/code has any type errors. I couldn't the right API for this, is there any?

Upvotes: 0

Views: 126

Answers (1)

Fabio Spampinato
Fabio Spampinato

Reputation: 717

It seems that errors can be detected like this:

const {Project} = require ( 'ts-simple-ast' );

const project = new Project ({
  tsConfigFilePath: 'tsconfig.json',
  addFilesFromTsConfig: false
});

project.addExistingSourceFiles ( 'dst/index.d.ts' );

const hasErrors = !!project.getPreEmitDiagnostics ().length;

Upvotes: 1

Related Questions