JS
TS
(Try it yourself - 5 minutes)
(5 minutes)
1. Function has 3 arguments, first, second and type
2. type is a string which can be
a. "add", "div", "mul", "sub"
It's not strict enough
Union operator
Union operator
TS vs JS
How does JS run code
TS vs JS
How does TS run code? It never does
It does
1. Type checking
2. converts to JS
The compiler is called - tsc
Let's bring the counter code locally
npm i -g tsc
tsc --init
ECMAScript version
1. es3, es5
very old (if u want to support IE)
2. ES2016 - ES2020
incrementally better
3. esnext
Latest
module type - target system
1. none
This isn't a module
2. commonjs
Node.js code
3. amd
browser code
Lets try commonjs vs es6
forceConsistentCasingInFileNames
Does casing matter when importing modules
strict
How strictly should TS be evaluated
(Person interface)
1. Let you accumulate data of a specific type
2. Interfaces can use other interfaces
3. Interfaces can extend interfaces
4. Interfaces can be implemented by classes
Very slightly different from interfaces
Need to be equated
Very useful for unions and ors
Can not be extended
Can mostly be used interchangibly
1. Interfaces can be implemented by classes
2. Interfaces can extend each other
3. Types can do unions and intersections