TypeScript theorytheory 0/50 · 0%
Foundations · easy

1. Why TypeScript

A typed superset of JavaScript that compiles to plain JS.

TypeScript adds a static type system on top of JavaScript. Every valid JavaScript file is already close to valid TypeScript; you opt in to types gradually, and the compiler (`tsc`) erases them to produce plain JS for the browser or Node.

The core promise is catching mistakes before runtime: typos in property names, wrong argument counts, and mismatched types are flagged in your editor as you type, instead of surfacing as a crash in production.

ts
function double(n: number): number {
  return n * 2;
}
double("5"); // compile error: string is not assignable to number

Because it compiles away, TypeScript has zero runtime cost — types exist only during development and are stripped out. This makes it attractive for web3 tooling, where a wrong type (e.g. passing a `string` where a `bigint` wei amount is expected) can cause expensive bugs.

Check your understanding

  1. 1. What happens to TypeScript's types when the code is compiled?

  2. 2. What is the main benefit of static typing?

  3. 3. Which statement is true about TypeScript and JavaScript?