Skip to content

Instantly share code, notes, and snippets.

@diverted247
Last active October 30, 2015 20:41
Show Gist options
  • Save diverted247/30c102020ffb576f3534 to your computer and use it in GitHub Desktop.
Save diverted247/30c102020ffb576f3534 to your computer and use it in GitHub Desktop.
Compiling TypeScript string within Nodejs Including Diagnostics
  • npm install
  • node index.js
var ts = require("typescript");
var content =
"import {f} from \"foo\"\n" +
"export var x = f()";
var compilerOptions = { module: ts.ModuleKind.CommonJS };
var res = ts.transpileModule( content , { compilerOptions: compilerOptions , moduleName: "myModule2" , reportDiagnostics:true } );
console.dir( res );
{
"name": "ts-compile",
"version": "1.0.0",
"description": "Compiling TypeScript string within Nodejs Including Diagnostics",
"main": "index.js",
"devDependencies": {
"typescript":"1.6.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment