Embed TypeScript code in an HTML document

Typescript

Typescript Problem Overview


Is it possible to embed TypeScript code in a web page? I want to embed TypeScript code inside script tags, like this (so that it is automatically compiled to Javascript):

<script type = "text/typescript">
    //TypeScript code goes here
</script>

Typescript Solutions


Solution 1 - Typescript

Actually there are several projects that allow you to use TypeScript code like that - TypeScript Compile, ts-htaccess.

The catch here is that .ts code should be compiled into JavaScript - it can be done either at client-side (slow; the whole TSC should be loaded into the client as well) or at server-side (obviously faster, and it's far easier to leverage the cache on the compiled code).

Solution 2 - Typescript

This is a version I wrote that directly uses the version from Microsoft/TypeScript/master so it always stays up to date: https://github.com/basarat/typescript-script

You can even point ts to any other TypeScript version you might have and it will work fine 

Solution 3 - Typescript

A JavaScript library has already been developed for this purpose - it's called TypeScript Compile, and it allows typescript to be embedded in HTML (as shown above.)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAnderson GreenView Question on Stackoverflow
Solution 1 - Typescriptraina77owView Answer on Stackoverflow
Solution 2 - TypescriptbasaratView Answer on Stackoverflow
Solution 3 - TypescriptAnderson GreenView Answer on Stackoverflow