References
Ideally, we could have a tool that helps us find these bugs before our code runs. That's what a static type-checker like TypeScript does.
Static types systems describe the shapes and behaviors of what our values will be when we run our programs. A type-checker like TypeScript uses that information and tells us when things might be going off the rails.
……
……
tsc --noEmitOnError hello.ts
function greet(person: string, date: Date) {
console.log(`Hello ${person}, today is ${date.toDateString()}!`);
}
greet("Maddison", new Date());
In many cases, TypeScript can even just infer (or "figure out") the types for us even if we omit them.
let msg = "hello there!";
……
By default TypeScript targets ES3.
The great majority of current browsers support ES2015.
Running with --target es2015
changes TypeScript to target ECMAScript 2015, meaning code should be able to run wherever ECMAScript 2015 is supported.
Most developers can therefore safely specify ES2015 or above as a target, …
Some people are looking for a more loose opt-in experience which can help validate only some parts of their program, and still have decent tooling.
… "strict": true
in a tsconfig.json
toggles …
most lenient type any
makes handling null
and undefined
more explicit, and spares us from worrying about whether we forgot to handle null
and undefined
.