go-typescript icon indicating copy to clipboard operation
go-typescript copied to clipboard

How can I make `TranspileCtx` return errors on invalid typescript.

Open bubbajoe opened this issue 1 year ago • 1 comments

For example, when i try to run this:

export { func: () => { } };

I expect there to be an error because this typescript is not valid, however it just returns invalid javascript.

Compiler Options:

{"alwaysStrict":true,"explainFiles":true,"module":"commonjs","noEmit":true,"noEmitOnError":true,"noErrorTruncation":true,"noLib":true,"target":"es5"}

bubbajoe avatar May 19 '24 03:05 bubbajoe

It looks like the Typescript function we use for transpile only returns the output text, not any diagnostics information so this technically isn't a bug.

https://github.com/microsoft/TypeScript/blob/79a851426c514a12a75b342e8dd2460ee6615f73/src/services/transpile.ts#L220

We could consider using the transpileModule function instead but that would be a breaking change so maybe we just make it configurable.

clarkmcc avatar May 20 '24 03:05 clarkmcc