1

I am new to transpiling TypeScript to JavaScript programmatically. So far, I am using TypeScript's transpileModule() function. This function takes a source string and transpiler options. I wanted to pass my tsconfig.json file as transpiler options, but this does not work, because there are slight differences (e.g. tsconfig.json uses string enums, wherease the compiler options use JavaScript enum enums).

Is there an easy way to convert between the two formats, e.g. like this:

transpileModule(tsString, configTsToTranspilerOptions(tsConfigJson));
Lehks
  • 2,582
  • 4
  • 19
  • 50
  • What about requiring this file, then taking its `compilerOptions` value? – raina77ow Aug 14 '22 at 10:15
  • 1
    That's what I did. But the required `compilerOptions` is incompatible to the `CompilerOptions` interface. E.g. in `tsconfig.json`, the property `jsx` is a string, but in `CompilerOptions` it is an `enum`. – Lehks Aug 14 '22 at 10:17
  • Is this question - https://stackoverflow.com/questions/67956755/how-to-compile-tsconfig-json-into-a-config-object-using-typescript-api - helpful? Checking the code shows that it returns `any` though, and not `CompilerOptions`. – raina77ow Aug 14 '22 at 10:19

0 Answers0