TypeScript Simple Types

TypeScript Simple Types
They help prevent errors and make code more readable.
number
Used for integers and floating-point numbers.
string
Used for text values.
boolean
Used for true / false values.
any
Allows any type of value (avoid using when possible).
- Use
anyonly when you don’t know the type.
unknown (Safer than any)
Requires type checking before use.
null and undefined
Used for empty or missing values.
With strictNullChecks:
array
Used to store multiple values of the same type.
tuple
Array with fixed number and type of elements.
enum
Defines a set of named constants.
void
Used when a function returns nothing.
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 |
