Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

typescript compile string to js

// compile.ts

import * as ts from "typescript";

function tsCompile(source: string, options: ts.TranspileOptions = null): string {
    // Default options -- you could also perform a merge, or use the project tsconfig.json
    if (null === options) {
        options = { compilerOptions: { module: ts.ModuleKind.CommonJS }};
    }
    return ts.transpileModule(source, options).outputText;
}

// Make sure it works
const source = "let foo: string  = 'bar'";

let result = tsCompile(source);

console.log(result); // var foo = 'bar';
Comment

PREVIOUS NEXT
Code Example
Javascript :: row auto textarea 
Javascript :: express formidable 
Javascript :: image compression in nodejs 
Javascript :: nodejs SSE 
Javascript :: find the largest array from an array in javascript 
Javascript :: fivem server discord.js 
Javascript :: loop into array javascript 
Javascript :: React timeago 
Javascript :: desestructuración javascript 
Javascript :: if mobile screen in js 
Javascript :: confirm alert 
Javascript :: table checkbox react 
Javascript :: how to access response headers in javascript fetch api 
Javascript :: .map method 
Javascript :: js spread parameters 
Javascript :: node.js generate certificate 
Javascript :: multiple refs react 
Javascript :: js string to num 
Javascript :: javascript await keyword 
Javascript :: frames[i] javascript 
Javascript :: !! js 
Javascript :: define component react with default props and props type 
Javascript :: js console log function code 
Javascript :: regular expression 
Javascript :: javascript object/function which you want to proxy 
Javascript :: fastest way to check a number is palindrome 
Javascript :: multiple images on cloudinary 
Javascript :: private router react v6 
Javascript :: react native time range picker 
Javascript :: js embedded function 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =