Capítulo 1 de 36
TypeScript is a static type system layered on JavaScript: it predicts what your code will do before it runs, catching a class of bugs (typos, uncalled functions, unreachable branches, wrong property access) that JavaScript itself only reports as runtime TypeErrors or silent undefineds.
undefined silently; TS errors).tsc: the TypeScript compiler. Installed via npm install -g typescript; tsc file.ts type-checks and emits a .js file.tsc strips them and downlevels newer syntax (e.g. template literals → string concatenation) to the configured target.noEmitOnError: by default tsc still emits JS even when type errors are found (useful mid-migration from JS). Turn this flag on to block emit on error.let msg = "hi" infers string) — don't annotate when inference already gets it right.strict flag (or "strict": true in tsconfig.json) toggles every strictness flag at once; each can also be opted in/out individually. The two most consequential:
noImplicitAny: errors when TS can't infer a type and silently falls back to any.strictNullChecks: stops null/undefined from being silently assignable to every other type.function greet(person: string, date: Date) {
console.log(`Hello ${person}, today is ${date.toDateString()}!`);
}
greet("Maddison", new Date());
person: string, date: Date) let TypeScript catch a call-site mistake — e.g. passing Date() (which returns a string in plain JS) instead of new Date() — at compile time instead of at runtime.| Flag | Effect |
|---|---|
strict | Enables every strictness flag at once |
noImplicitAny | Errors on any value TS can't infer and would otherwise silently type as any |
strictNullChecks | null/undefined are no longer assignable to arbitrary types by default |
noEmitOnError | Blocks .js output when type errors are present |
target | Sets the ECMAScript version tsc downlevels/compiles to (default ES5; most projects can safely target ES2015+) |
strict on from day one — it costs a bit of upfront annotation work but pays back in caught bugs and better tooling.tsc emitting despite errors is intentional (great for incremental JS→TS migration); use noEmitOnError once you want it to act as a hard gate.tsconfig.json / Choosing Compiler Options: where strict, target, and friends are actually configured for a project.