Workspace

TypeScript

typed JavaScript for product scale

Definition first

What TypeScript means

TypeScript is a programming language for writing exact instructions, often used for typed JavaScript for product scale. Start with one mental model: input goes through steps and becomes output.

Minimum run factsFile app.tsRun tsc app.ts && node app.jsHabit Let the type error teach the missing contract
Program

An ordered set of instructions. It reads input, follows rules, and produces output.

Value and variable

A value is data. A variable is the name you use to hold and reuse that data.

Function

A named piece of work. It takes input, does one job, and can return a result.

Runtime

TypeScript compiler then Node.js is the place that actually runs code from app.ts.

First readable code

Typed values

string number boolean array object
const name: string = "Ada";
console.log(name);
Output Ada

Language lineage

TypeScript family tree

See where TypeScript comes from, which languages feel close, and what to learn next.

roots
JavaScriptJavaC#
currentTypeScriptTyped JavaScript family
familyTyped JavaScript family
best used for

large JavaScript products where refactors and API contracts matter

Zero base path

1Read one rule2Predict output3Type from memory4Run checklist5Repeat with one change

Question bank

Search before practice

Pick a stage or search across the open programming bank. Jump straight to the matching drill.

18 matching questions
Q 1ChoiceStage 1 definitions

TypeScript practice 1

TypeScript question 1. Choose the statement that matches type annotation.

Q 2ChoiceStage 1 definitions

TypeScript practice 2

TypeScript question 2. Choose the statement that matches interface shape.

Q 3ChoiceStage 1 definitions

TypeScript practice 3

TypeScript question 3. Choose the statement that matches union narrowing.

Q 4ChoiceStage 1 definitions

TypeScript practice 4

TypeScript question 4. Choose the statement that matches generic array.

Q 5ChoiceStage 1 definitions

TypeScript practice 5

TypeScript question 5. Choose the statement that matches type annotation.

Q 6ChoiceStage 1 definitions

TypeScript practice 6

TypeScript question 6. Choose the statement that matches interface shape.

Q 7ChoiceStage 1 definitions

TypeScript practice 7

TypeScript question 7. Choose the statement that matches union narrowing.

Q 8ChoiceStage 1 definitions

TypeScript practice 8

TypeScript question 8. Choose the statement that matches generic array.

Q 9ChoiceStage 1 definitions

TypeScript practice 9

TypeScript question 9. Choose the statement that matches type annotation.

Q 10ChoiceStage 1 definitions

TypeScript practice 10

TypeScript question 10. Choose the statement that matches interface shape.

Q 11ChoiceStage 1 definitions

TypeScript practice 11

TypeScript question 11. Choose the statement that matches union narrowing.

Q 12ChoiceStage 1 definitions

TypeScript practice 12

TypeScript question 12. Choose the statement that matches generic array.

Q 13ChoiceStage 1 definitions

TypeScript practice 13

TypeScript question 13. Choose the statement that matches type annotation.

Q 14ChoiceStage 1 definitions

TypeScript practice 14

TypeScript question 14. Choose the statement that matches interface shape.

Q 15ChoiceStage 1 definitions

TypeScript practice 15

TypeScript question 15. Choose the statement that matches union narrowing.

Q 16ChoiceStage 1 definitions

TypeScript practice 16

TypeScript question 16. Choose the statement that matches generic array.

Q 17ChoiceStage 1 definitions

TypeScript practice 17

TypeScript question 17. Choose the statement that matches type annotation.

Q 18ChoiceStage 1 definitions

TypeScript practice 18

TypeScript question 18. Choose the statement that matches interface shape.

Multiple choice

TypeScript practice 1

Q 1Choicenew

TypeScript question 1. Choose the statement that matches type annotation.

const age: number = 18;

Reference

Patterns for app.ts

TypeScript compiler then Node.jstsc app.ts && node app.js
Recall from memoryRead a small point then write it back without looking
Trace the codeWrite variable values line by line before you run the answer
Type it yourselfCopy less type more and fix one small error at a time

string number boolean array object

Typed values

const name: string = "Ada";
console.log(name);
  • Type public data shapes
  • Let local inference work
  • Fix red squiggles early

object contracts reusable shapes

Interfaces

interface User { name: string }
const user: User = { name: "Ada" };
console.log(user.name);
  • Interfaces describe object shape
  • Prefer exact fields
  • Use readable names

unknown union guard safe access

Narrowing

function label(x: string | number) {
  return typeof x === "string" ? x.toUpperCase() : x + 1;
}
  • Check before using
  • Use typeof and in
  • Avoid any when learning