TypeScript Hindi Tutorial: #3 - All Data Types Explained
What is DataTypes?
- Primitive Types
- Object Types
- Special Types
- Advanced Types
- Function Types
๐น Basic Data Types
number : Represents all numbers (integers, floats, hex, binary, octal).
string : Used for text (with single, double, or backticks for template strings).
boolean : Represents true/false values.
๐น Special Types
any : Can hold any type (not recommended unless necessary).
unknown: Similar to any, but safer (forces type-checking before usage).
void: Usually for functions that donโt return anything.
never: Represents values that never occur (e.g., function that always throws error).
๐น Object & Collection Types
Arrays: Can be written as type[] or Array<type>.
Tuples: Fixed length & order array with specific types.
Enums:A set of named constants.
๐น Advanced Types
Union (|) : Variable can be multiple types.
Intersection (&): Combines multiple types into one.
Type Aliases:Create your own type shortcuts.
Literal Types:Restrict values to exact strings/numbers.
โ In short:
Basic types: number, string, boolean
Special types: any, unknown, void, never
Data structures: object, array, tuple, enum
Advanced: union, intersection, type alias, literals