Transpile TypeScript to javaScript

TypeScript is a super set of JavaScript, brought to us by Microsoft.

Browsers can’t run TypeScript yet it is needed for Angular2+. So it is necessary to convert or ‘transpile’ your TypeScript code to JavaScript to that it will run in a browser, if you need it to run in a browser that is.

Start by intsalling typescript

$ npm install -g typescript

make a typescript file, e.g. filename.ts

let num: number = 4;

transpile with,

$ tsc filename.ts

and you’ll get a new file filename.js

var number = 4;

and that’s it!

What’s great about typescript is it gives you the errors on transpile.

Try this in your file,

console.log(blah);

without defining blah so that you get an error.

Note that the file will still run despite error showing.