Data-Types

The primitive, non-primitive, and special types in TypeScript, plus the built-in utility types and when to use arrow vs regular functions.

Primitives

  • String, Number, BigInt, Null, Undefined, Symbol. Total - 7
    • Number is 64-bit floating point.
    • BigInt is an integer size limited by the memory allotted. No decimal in this

Non-Primitives

  1. Object - key value pairs. Keys can be string only.
  2. Arrays - Arrays in typescript hold values of same type. In javascript its flexible and can hold any datatype.
  3. Tuple - Fixed length (Might not allow add values if strict). Type is fixed at a position. const tuple: [string, number] = ["Adesh", 30]
  4. Function
  5. Class
  6. Interface
  7. Type Alias
  8. Enum - Set of named constants
  9. Map / Set
  10. 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

  1. any: Disables the type-checking. Use only when necessary.
  2. unknown: Marks as type is not known, but type needs to be narrowed before using the variable.
  3. 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 thrown.
  4. void: Used for functions that do not return.
  5. null and undefined: Can be used explicitly, ( in strict mode ). Config might not allow null.
  6. object: Any non-primitive object. Excludes all the primitives, and includes all the non-primitives like arrays, functions, etc.
  7. {}: Allows everything including primitives, just excluding - null or undefined.
  8. 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.esnext or lib.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
Adesh Tamrakar
SOFTWARE ENGINEER · VAULT

Notes, insights and random discoveries from a working engineer's vault - written for future me, published for you.