Sikau

TypeScript · Day 1 · about 20 min

Why TypeScript?

Catch mistakes before you run your code.

JavaScript, with a spell-checker

In JavaScript, "5" + 1 quietly becomes "51", and calling a function with the wrong thing only fails when that line runs — maybe in front of a user. TypeScript is JavaScript plus types: you describe what kind of value goes where, and it warns you about mistakes *while you type*.

Your first type

let price: number = 180;
price = "free";

function double(n: number) {
  return n * 2;
}
console.log(double(21));
console.log(double("21"));
  • TypeScript files end in .ts. Browsers can't run them directly — they're compiled to plain JavaScript first, and the types are removed.
  • Types cost nothing at runtime. They exist only to help you while you write.
  • Every JavaScript program is (almost) valid TypeScript, so you can adopt it gradually.

In Sikau, TypeScript lessons type-check your code in strict mode — the setting professionals use.

The rest of this lesson

  • What a type error looks likeexplain
  • Where TypeScript fitsexplain
  • Will TypeScript complain?predict
  • Read the errormatch
  • Your turnwrite code
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 24 lessons of TypeScript