Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile a TypeScript String to a Javascript String programmatically

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 ?

like image 505
Angelos Pikoulas Avatar asked Jul 31 '13 08:07

Angelos Pikoulas


1 Answers

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

like image 87
basarat Avatar answered Sep 30 '22 09:09

basarat