Compile a TypeScript String to a Javascript String programmatically

我的未来我决定 提交于 2019-12-04 03:49:01

问题


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:


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



来源:https://stackoverflow.com/questions/17965572/compile-a-typescript-string-to-a-javascript-string-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!