Compile a TypeScript String to a Javascript String

2019-02-23 18:30发布

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

For instance, in Coffeescript (and LiveScript, coco etc) its a (simplified) one-liner:

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

Can something similar be implemented for TypeScript, preferably without involving the filesystem ? Are there any implications with referencing other modules that would have to be resolved at compile time ?

1条回答
迷人小祖宗
2楼-- · 2019-02-23 18:49

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

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

查看更多
登录 后发表回答