TypeScript Crash Course By Traversy Media
Edilson Alexandre Cuamba
-
What is it?
- An open source language;
- A superset of JavaScript(ECMAScript);
-
Advantages
- Offer additional features to JavaScript including static types;
- Using types is completely optional;
- Comiles down to regular JS;
- Can be used for front-end JavaScript as well as backend with Node.JS;
- Includes most features from ES6 and ES7 (classes, arrow functions, etc);
- Types from 3rd party librares can be added with type definitions;
-
Dynamic vs Static Type Languages
- In dynamic type languages, the type are associated with run-time values and not named explicitly in your code.
- In static type languages, you explicitly assign types to variables, function parameters, return values, etc;
Static Examples are: Java, C, C++, Rust, GO
Dynamic Examples are: JavaScript, Python, Ruby, PHP
Pros & Cons
Pros
- More Robust;
- Easily Spot Bugs;
- Predicability;
- Readability;
- Popular;
Cons
- More Code To Write;
- More to Learn;
- Required Compilation;
- Not True Static Typing;
Use it for large project or with project that you will work with a lot of people.
Compiling TypeScript
- Uses .ts and .tsx as extensions;
- TSC (TypeScript COmpiler) is used to compile .ts files down to .js files;
- Can watch fies and report error at compile time;
- Many tools include TS compilation by default;
- Most IDEs have great support for TS;
- The tsconfig.json file is used to configure how TypeScript works;