Skip to content

Instantly share code, notes, and snippets.

@marcelmokos
Last active March 22, 2022 13:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save marcelmokos/bc28d39f76cfa777e5b62949b0da3edf to your computer and use it in GitHub Desktop.
Save marcelmokos/bc28d39f76cfa777e5b62949b0da3edf to your computer and use it in GitHub Desktop.
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