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.
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.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With