Skip to content

TomasHubelbauer/typescript-in-browser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TypeScript in the Browser

Note: The ability to both transpile and execute TypeScript code in the browser has since been added to the TypeScript Playground: https://www.typescriptlang.org/play

This repository is an experiment in transpiling TypeScript in the browser.

DEMO

How does it work?

  1. The page loads typescript.js (typescript/lib/) in some way (CDN, node_modules)
  2. The page has the TypeScript and ts objects available on window
  3. The TypeScript API can be used
  4. This demo transpiles TypeScript source text to JavaScript source text based on the demo in the TypeScript wiki
const { outputText, diagnostics, sourceMapText } = ts.transpileModule('const x: number = 5;', { compilerOptions: { target: 'esnext' } });

Running

Remotely, see the online demo

Locally, run index.html

To-Do

Make TSX work in the Monaco editor

Add TS compiler options controls: types, target etc.

Investigate how loading typings could work