Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transpileModule() does not generate diagnostics #4864

Closed
guyellis opened this issue Sep 18, 2015 · 3 comments
Closed

transpileModule() does not generate diagnostics #4864

guyellis opened this issue Sep 18, 2015 · 3 comments
Labels
API Relates to the public API for TypeScript Question An issue which isn't directly actionable in code

Comments

@guyellis
Copy link

I would have expected the following console.log statement to have produced an array with at least 1 element. Running this on Typescript 1.6.2 does not produce anything.

var ts = require('typescript');

var content = 'var x: number = "string"';
var transpileOptions = {
  compilerOptions: {
    module: ts.ModuleKind.CommonJS
  },
  reportDiagnostics: true
};

var result = ts.transpileModule(content, transpileOptions);

console.log(result.diagnostics);

(Executed with node test.js)

@vladima
Copy link
Contributor

vladima commented Sep 18, 2015

transpileModule/transpile currently report only syntactic errors. Semantic errors are not reported since if it will yield tons of false positives i.e. we compile standalone file that has imports or uses something that should exists globally (even types from standard library). To summarize: current behavior is by design, in theory we can still collect semantic errors and expose then via different property, so user can differentiate between syntactic errors (which are real errors) and semantic errors (that are most likely appear because some name cannot be resolved in single file compilation scenario). If you think that having such functionality will be valuable - please file a suggestion issue for this.

@vladima vladima closed this as completed Sep 18, 2015
@guyellis
Copy link
Author

In version 1.4.1 we were able to get these errors by calling ts.createProgram(...) and then getDiagnostics() on the object returned by createProgram(). How do we get that type of information in 1.6.2?

@vladima
Copy link
Contributor

vladima commented Sep 18, 2015

Program should expose a set of methods to query for diagnostics:

        getGlobalDiagnostics(cancellationToken?: CancellationToken): Diagnostic[];
        getSyntacticDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): Diagnostic[];
        getSemanticDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): Diagnostic[];
        getDeclarationDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): Diagnostic[];

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
API Relates to the public API for TypeScript Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

3 participants