2016-10-30 my learning notes.
# instal npm install -g typescript
TypeScript filename extension is “.ts”.
const f = (x => [x + 1]); const m = 4; document.body.innerHTML = f(m);
Name the file “test.ts”.
in terminal, type
# TypeScript compile file to js tsc test.ts
ES2015 to target ES5 Flags
TypeScript has flags that control how you want the ouput.
Here's basic flag config for compiling ES2015 to ES5.
# TypeScript basic config for compiling ES2015 to ES5 js tsc --alwaysStrict --lib DOM,ES2015,DOM.Iterable,ScriptHost --target ES5 test.js
You might get errors such as
error TS2322: Type 'any' is not assignable to type 'string'.
but don't worry about type errors. It'll still compile.
Currently, we are only interested in compiling ES2015 js to ES5.
later on, you can add types to your js so the errors don't show. Or, add declarations to suppress some errors.
ES2015 Features TypeScript Won't Translate
TypeScript only does syntactic transformation.
Things it does not compile to ES5 are ES2015 objects.
When you have these objects, TypeScript leaves them as is.
If you have a question, put $5 at patreon and message me.