Last active
March 22, 2022 13:40
-
-
Save marcelmokos/bc28d39f76cfa777e5b62949b0da3edf to your computer and use it in GitHub Desktop.
Typescript Basic Types table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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