clarkmcc / go-typescript

Compile and run Typescript code natively in Go
GNU General Public License v3.0
101 stars 11 forks source link

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

Open bubbajoe opened 2 months ago

bubbajoe commented 2 months ago

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"}
clarkmcc commented 2 months ago

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.