Skip to content

Instantly share code, notes, and snippets.

@marcelmokos
Last active September 9, 2024 05:13
Show Gist options
  • Select an option

  • Save marcelmokos/bc28d39f76cfa777e5b62949b0da3edf to your computer and use it in GitHub Desktop.

Select an option

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) {}; };

ghost commented Sep 9, 2024

Copy link
Copy Markdown

I could be wrong, but date should also be included here. Thanks for this table tho <3. Re-learning typescript after not using it for 3 years is kinda wonky.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment