let a: string, b: any
— Basic type annotations
Literal types: let dog = { id: 1 }
→ { id: number }
Type alias: type User = { id: number }
Interface (Extensible):
interface Influencer extends User {
budget: number
}
null
is a subtype of all types: let a: number = null
never
type: type Tree = { flesh: never }
readonly
properties: type User = { id: readonly string }
unknown
: unlike any
, it has to be asserted before use.function fn(x? : number = 10) {}
enum UI { React, Vue, Angular }
let z = UI.Angular // 2
let x = y as string
ele!.focus() // non-null assertion
type Cat = { name: string }
type Domestic = { owner: string }
let kitty: Cat & Domestic //extends Both
let x: boolean | string // one of list
let p: [string, number] //fixed length typed array
let k = 2, v = true
let z = [k, v] as const // [2, true] <-- most narrow type possible