TYPESCRIPT
TYPESCRIPT
DATATYPES
1. BASIC TYPES
anything = "Hello";
console.log(message);
2. ARRAY
3. TUPLE
Tuples allow you to express an array with a fixed number of elements whose types are known.
4. ENUM
Enums allow a developer to define a set of named constants.
enum Color {
Red,
Green,
Blue
5. OBJECT
Objects are collections of key-value pairs.
name: "Alice",
age: 25
};
6. UNION TYPES
Union types allow a variable to have one of several types.
value = "Hello"; // OK
7. TYPE ALIASES
Type aliases create a new name for a type.
userId = 123; // OK
userId = "abc"; // OK
8. INTERFACES
Interfaces define the structure of an object. They are similar to type aliases but are more powerful when
it comes to describing object shapes.
interface User {
name: string;
age: number;
name: "Alice",
age: 25
};
9. FUNCTIONS
TypeScript allows you to specify types for function parameters and return values.
return a + b;
10. GENERICS
Generics allow you to create reusable components.
function identity<T>(arg: T): T {
return arg;
1. Type Inference: TypeScript automatically infers the type based on the value assigned.
interface Person {
name: string;
interface Car {
model: string;