Primitives
- String, Number, BigInt, Null, Undefined, Symbol. Total - 7
- Number is 64-bit floating point.
- BigInt is a integer size limited by the memory alloted. No decimal in this
Non-Primitives
- Object - key value pairs. With keys can be string only.
- Arrays - Arrays in typescript holds values of same type. In javascript its flexible and can hold any datatype.
- Tuple - Fixed length (Might not allow add values if strict). Type is fixed at a position.
const tuple: [string, number] = ["Adesh", 30] - Function
- Class
- Interface
- Type Alias
- Enum - Set of named constants
- Map / Set
- Promise
🔢 Numeric Literal Prefixes
| Format | Prefix | Example | Base |
|---|---|---|---|
| Decimal | (none) | 42 | 10 |
| Binary | 0b | 0b1010 | 2 |
| Octal | 0o | 0o52 | 8 |
| Hexadecimal | 0x | 0x2A | 16 |
Special Types
any: Disables the type-checking. Use only when necessary.unknown: Marks as type is not known, but type needs to be narrowed before using the variable.never: Represents a value that never occurs. A function that throws error for edge cases. So ideally / programmatically it should not occur. But, in case something fails, the function is called, and a custom error is throwed.void: Used for functions that do not return.nullandundefined: Can be used explicitly, ( in strict mode ). Config might not allow null.object: Any non-primitive object. Excludes all the primitives, and includes all the non-primitives like arrays, functions, etc.{}: Allows everything including primitives, just excluding -nullorundefined.Record: Use this to specify plain objects with key value pairs.Record<string, number>a plain object that can only have string type keys and number type values.
Utility Types
🔹 1. Type Transformation Utilities
| Utility Type | Description |
|---|---|
Partial<T> | Makes all properties in T optional. |
Required<T> | Makes all properties in T required. |
Readonly<T> | Makes all properties in T read-only. |
Mutable<T> | (from TS 5.2+ with lib.esnext) Makes all properties writable. |
Pick<T, K> | Picks a set of properties K from T. |
Omit<T, K> | Removes properties K from T. |
Record<K, T> | Constructs an object type with keys of type K and values of type T. |
🔹 2. Type Filtering / Conditional Utilities
| Utility Type | Description |
|---|---|
Exclude<T, U> | Excludes from T those types that are assignable to U. |
Extract<T, U> | Extracts from T those types that are assignable to U. |
NonNullable<T> | Removes null and undefined from T. |
🔹 3. Function Type Utilities
| Utility Type | Description |
|---|---|
Parameters<T> | Extracts the parameter types of a function type T. |
ConstructorParameters<T> | Extracts constructor parameter types. |
ReturnType<T> | Gets the return type of a function type. |
InstanceType<T> | Gets the instance type of a constructor function type. |
ThisParameterType<T> | Gets the type of the this parameter for a function. |
OmitThisParameter<T> | Removes the this parameter from a function type. |
ThisType<T> | A marker for this type in object literals (used with noImplicitThis). |
🔹 4. Promise & Async Utilities
| Utility Type | Description |
|---|---|
Awaited<T> | Gets the resolved type of a Promise<T>. Useful for async/await. |
🔹 5. New Utility Types (TypeScript 5.x)
Some newer utility types are available when targeting
lib.esnextorlib.dom:
| Utility Type | Description |
|---|---|
Writable<T> | (TS 5.2+) Removes readonly from properties. (Similar to custom Mutable) |
ReadonlyDeep<T> | (Community libs) Deep-readonly version (not built-in yet). |
🔹 Bonus: Useful Custom Utility Types (You can write)
| Name | Description |
|---|---|
DeepPartial<T> | Makes all nested properties optional. |
UnionToIntersection<U> | Converts union type to intersection. |
These are not built-in but very commonly used in advanced TS setups.
Arrow functions vs Functions
| Use Arrow Functions When… |
|---|
You need lexical this |
Writing simple callbacks (e.g., .map, .filter) |
Inside React components (useEffect, handlers) |
| You want to avoid accidental re-declarations |
Use Regular function When… |
|---|
You need this or arguments |
| You’re writing top-level reusable functions |
| You need to overload function signatures |
| You’re writing class methods |