Learn TypeScript in Your Browser

No setup required! Learn type-safe coding through interactive exercises

string
number
boolean

Primitive Types

Basic types like boolean, number, string

basicsBeginner
type StringOrNumber =
string | number

Type Aliases

Give a new name to existing types

basicsBeginner
number[]
Array<string>

Array Types

Array literals and type annotations

basicsBeginner
let tuple:
[string, number]

Tuple Types

Arrays with fixed length and element types

basicsBeginner
{ name: string;
age: number }

Object Types

Object literals and type annotations

basicsBeginner
{ name: string;
age?: number }

Optional Properties

Define properties that can be omitted

basicsBeginner
{ readonly name: string;
age: number }

Readonly Properties

Read-only properties

basicsBeginner

💡 Learning Tips

  • • First, run the code to check how it works
  • • Read error messages carefully to understand what the problem is
  • • It's important to think for yourself before viewing the solution
  • • Try modifying the code to see how it behaves