Boolean
let isBool: boolean = True; //true/flase
Number
let num: number = 7;
let hexNum: number = 0xf0c0;
let binaryNum: number = 0b00100;
let octalNum: number = 0o23;
String
let str: string = "hello";
let sentence: string = ':) ${str} world';
Array
let list: number\[\] = \[1,2,3\];
let list: arry = \['a', 'b', 'c'\]
Tuple
let a: \[number, string\];
Enum
enum abc {a, b, c}
let a: abc = abc.a;
let num: string = abc\[0\];
Any
let a: any = 7;
a = "hello";
a = true
let list: any\[\] = \[7, true, "hello"\]
void
function func(): void {
a = " nothing return "
}
Null & Undefined
let a: undefined = undefined;
let b: null = null;
Never
function error(message: string): never {
throw new Error(message);
}
Type assertions
let somthing: any = "string";
let change: str= <string>someValue;
let change: str= someValue as string;