TypeScript Simple Types
🧩 TypeScript Simple Types
They help prevent errors and make code more readable.
1️⃣ number
Used for integers and floating-point numbers.
2️⃣ string
Used for text values.
3️⃣ boolean
Used for true / false values.
4️⃣ any
Allows any type of value (avoid using when possible).
📌 Use any only when you don’t know the type.
5️⃣ unknown (Safer than any)
Requires type checking before use.
6️⃣ null and undefined
Used for empty or missing values.
With strictNullChecks:
7️⃣ array
Used to store multiple values of the same type.
8️⃣ tuple
Array with fixed number and type of elements.
9️⃣ enum
Defines a set of named constants.
🔟 void
Used when a function returns nothing.
1️⃣1️⃣ never
Used when a function never returns.
📌 Type Inference
TypeScript can automatically detect types.
🔍 Simple Types Summary
| Type | Purpose |
|---|---|
| number | Numeric values |
| string | Text |
| boolean | true/false |
| any | Any type |
| unknown | Safe any |
| null | Empty |
| undefined | Not assigned |
| array | List of values |
| tuple | Fixed structure |
| enum | Named constants |
| void | No return |
| never | Never returns |
