Compile TypeScript String into Javascript String programmatically

Is there a way to compile a String containing TypeScript, my equivalent JavaScript String ?

For example, in Coffeescript (and LiveScript, coco, etc.) its (simplified) single-line:

jsCompiledCode = require('coffee-script').compile('do -> console.log "Hello world"', {bare:true});

Could something like this be implemented for TypeScript, preferably without involving a file system? Are there any consequences for references to other modules that would need to be resolved at compile time?

+4
source share
1 answer

You can use TypeScript.Api nodejs package: https://npmjs.org/package/typescript.api

In particular, check out this feature: https://github.com/sinclairzx81/typescript.api#compile

+3
source

Source: https://habr.com/ru/post/1494450/


All Articles