Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Typescript Basic Types table
Javascript type constructor example values typescript type example usage alternative syntax
Boolean Boolean(1); true, false boolean const isOpen: boolean = true;
Number Number('1'); 1, 2 number const n: number = 1;
String String('');, '',", `` 'ok' string const str: string = 'ok';
Array new Array(); []; [1, 2, 3]; number[]; Array<number>; const list: number[] = [1, 2, 3]; const list: Array<number> = [1, 2, 3];
Null null null null const n: null = null;
Undefined undefined undefined undefined const u: undefined = undefined;
Object new Object(); {key: 'value'}; object const item: object = {key: 'value'}; const item: {[key: string]: string} = {key: 'value'};
['Hello', true]; Touple const hi: [string, boolean] = ['Hello', true]
enum enum Color {Red, Green, Blue}
any let x: any = 4; x = ''; x = false;
void function log(): void => {}; const fn = (): void => {};
never const error = (): never => { throw new Error(); }; const fn = (): never => { while (true) {}; };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment