Typescript datatypes

From wikinotes
Revision as of 03:16, 11 December 2022 by Will (talk | contribs)

Primitives

string
number
boolean

Object Types

You can define sort-of anonymous interfaces, based on the properties you require.

function volume(coords: { x: number; y: number; z: number; }): number {
    // ...
}

Unions

A param accepting a variety of types.

function print(msg: number | string | boolean): null {
    console.log(msg)
}