0

Hi I'm using the clearscript V8 engine and want to enable TypeScript.

Following this post I'm able to load the https://rawgit.com/Microsoft/TypeScript/master/lib/typescriptServices.js javascript code into V8 and use that to transpile typescript code, but is seems to use an old version ES3 as a default target for the transpiled js.

How can I set the transpilation target to ES2021? All guidance is about tsconfig used with tsc.exe but I can't seem to figure out how to do this when using typescript.js straight in V8.

gjvdkamp
  • 9,929
  • 3
  • 38
  • 46
  • For anyone who comes after, [here] (https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-Api) is some guidance from ms on how to use the ts api, the first example shows how to set the target. – gjvdkamp Nov 01 '21 at 19:26

1 Answers1

1

The transpile function actually looks like this:

function transpile(input, compilerOptions, fileName, diagnostics, moduleName) { ... }

My guess is that compilerOptions is expected to be a JavaScript object that complies with the TSConfig compilerOptions reference.

UPDATE: Try something like ts.transpile(code, { target: 'es2021' }).

BitCortex
  • 3,328
  • 1
  • 15
  • 19
  • will check asap, that seems promising indeed. – gjvdkamp Nov 01 '21 at 15:02
  • Also found this https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-Api from Microsoft, first example shows (at least one way) how to set the target. – gjvdkamp Nov 01 '21 at 19:27