Having worked a bit with ClearScript, the idea is pretty cool to make it work.
To get the code, at least a little more work: Instead of using tsc.js, just use typescript.js , which comes with the SDK and should be in the same folder.
var typeScriptSource = File.ReadAllText("typescript.js");
typescript.js is a simple javascript compiler where tsc uses WSH and other com objects ...
So you can also use a V8 engine!
But in any case, this means that you have to code some JavaScript to actually wrap the TypeScript.TypeScriptCompiler functions.
So this means that you have to do the same thing as if you were using TypeScriptCompiler on your custom html page (e.g. on the playground). I could not find the documentation on how to use the compiler so far, though ... But I found one page that also tries to implement this http://10consulting.com/2012/10/12/introduction-to-typescript- presentation / If you look at the source of the presentation, you will find a compiler class.
Compiler.prototype.compile = function (src) { var outfile = { source: "", Write: function (s) { this.source += s; }, WriteLine: function (s) { this.source += s + "\n"; }, Close: function () { } }; var compiler = new TypeScript.TypeScriptCompiler(outfile); try { compiler.parser.errorRecovery = true; compiler.setErrorCallback(function (start, len, message, block) { console.log('Compilation error: ', message, '\n Code block: ', block, ' Start position: ', start, ' Length: ', len); }); compiler.addUnit(Compiler.libfile, 'lib.d.ts'); compiler.addUnit(src, ''); compiler.typeCheck(); compiler.emit(false, function createFile(fileName) { console.log(outfile); return outfile; }); console.log('compiled: ' + outfile.source); return outfile.source; } catch (e) { console.log('Fatal error: ', e); } return ''; }; return Compiler;
This looks pretty promising, but unfortunately, if I try to use it with ClearScript, it causes strange errors, maybe I'm doing something wrong ...
At least if I am debugging the code, js.Scripts.TypeScript is defined and contains all TypeScript objects!
In any case, I think this should take you a step forward;) let me know if you had success!
Alternatively, you can use the command line tool to simply call the compiler instead of doing it from within C # directly. I suppose this should be easier to implement ... Or play with the node.js package, which also provides you with all the necessary compiler services.