In TypeScript, data types include number, string, boolean, enum, any, void, null, and undefined. These data types help in defining the type of values that can be assigned to variables and functions, allowing for better type safety and error checking.
Additionally, TypeScript also supports array, tuple, object, interface, and more complex data types, providing developers with flexibility and control when working with different types of data.
let num: number = 5;
let name: string = 'John';
let isValid: boolean = true;
let list: number[] = [1, 2, 3];
let person: [string, number] = ['John', 25];
enum Color {Red, Green, Blue};
let anyValue: any = 4;
let unusable: void = undefined;
let n: null = null;
let u: undefined = undefined;
function throwError(message: string): never {
throw new Error(message);
}
let obj: object = { key: 'value' };