Type labels
A variable is a named box for a value. In TypeScript you can label the box with a type, written after a colon: user: string. The label says which kind of value the box may ever hold.
Everyday types
A string is text, written in quotes. "Mia" is a string, so tsc lets it into the user box. Any text fits: an empty "", a single letter or a whole sentence.
number is for every number: 12, -3 and 12.5 are all numbers. JavaScript has no separate type for whole numbers, so TypeScript has no int or float. 12 goes into age.
boolean has only two values, true and false, for yes-or-no facts such as whether Mia is a member. Type names are lowercase: write boolean, not Boolean.
number[] is an array type: a list in which every item is a number. Line 4 stores the list [90, 85] in scores. Array<number> is another way to write the same type.
push adds an item to the end of an array. tsc checks the item too: 70 is a number, so scores grows to [90, 85, 70]. Pushing the string "A" would be an error.
The check
Line 6 tries to put the string "twelve" into age, but age is a number. tsc stops it before anything runs: Type 'string' is not assignable to type 'number'.
Change it to the number 13 and the check passes. A box can get new values, but its type never changes: age must always hold a number.
The labels exist only for the check. When tsc writes the JavaScript file it removes every annotation, so : number disappears and only the values are left for the running program.
What happens
;; step 1/9 · label line 1: let user: string = "Mia"; let make a new variable (a box) user its name : string its type annotation (the label) = "Mia" the value to put in
There is also a type called any. It switches the check off for that box, so any value goes in. It is an escape hatch; avoid it while you learn. You can often leave the label off: let age = 12 still makes age a number, because tsc works it out from the value. The next lesson is about this.