Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run TypeScript compiler within a website

I'd like to run the TypeScript compiler within a website in order to build something like the playground on TypeScript's website TypeScript Playground.

In opposite of running tsc on the server side, I'd like to run compile it directly within JS. I've looked for any similar posts here and any description within the TypeScript language specification, but I can't find any information on that.

like image 847
Thorsten Hans Avatar asked Jan 29 '13 16:01

Thorsten Hans


People also ask

How do I run a TypeScript script?

We can use the ts-node package to execute TypeScript files from the command line. Install it with npm or other package manager. After that, simply execute the TypeScript files with the command: ts-node filename.


2 Answers

The typescript compiler is written in Typescript, so you can load the compiler (typescript.js) into your browser. But bare in mind that it is slightly heavy (roughly 250 KB).

like image 92
ppoliani Avatar answered Oct 02 '22 14:10

ppoliani


There's some documentation on the TS Compiler API and there's also typestring - a wrapper that is still intended for use in NodeJS, but you can use it as a starting point.

like image 26
Paul Avatar answered Oct 02 '22 14:10

Paul