📚 TypeScript Basics

⚠️

This section is a work in progress.

💡

This guide is not meant to be an introduction to programming in general, and assumes you have some baseline familiarity with other languages.

Literals

// number
123
// string
"abc"
'def'
`ghi ${ /* supports interpolation */ } jkl`
// boolean
true
false
// null & undefined
null
undefined

Arrays

const strArr: string[] = ['a', 'b', 'c']
// (arrays are 0-indexed)
strArr[0] // => 'a'
strArr[1] // => 'b'

Objects

const obj: Record<string, number> = {
a: 1,
b: 2,
c: 3,
}
obj.a // => 1
obj['b'] // => 2

Functions

// function-style
function square(x: number): number {
return x * x
}
// arrow-style
const square = (x: number): number => {
return x * x
}
// inline arrow-style
const square = (x: number): number => x * x
// without types (JavaScript-like)
const square = (x) => x * x

Arithmetic

Array functions

Control structures

Promises (async / await)