Comprehensive list of built-in utility types in TypeScript with a brief descriptio and examples for each:


TypeScript’s Built-in Utility Types

1. Partial<Type>

Makes all properties of Type optional.

interface User { name: string; age: number; }
type PartialUser = Partial<User>; // { name?: string; age?: number }

2. Required<Type>

Makes all properties of Type required (opposite of Partial).

type RequiredUser = Required<PartialUser>; // { name: string; age: number }

3. Readonly<Type>

Makes all properties of Type read-only.

type ReadonlyUser = Readonly<User>; // { readonly name: string; readonly age: number }

4. Record<Keys, Type>

Creates an object type with keys from Keys and values of Type.

type UserMap = Record<string, User>; // { [key: string]: User }

5. Pick<Type, Keys>

Selects a subset of properties from Type using Keys.

type UserName = Pick<User, 'name'>; // { name: string }

6. Omit<Type, Keys>

Removes properties Keys from Type.

type AgelessUser = Omit<User, 'age'>; // { name: string }

7. Exclude<UnionType, ExcludedMembers>

Removes types from a union.

type T = Exclude<'a' | 'b' | 'c', 'a'>; // 'b' | 'c'

8. Extract<UnionType, ExtractableMembers>

Keeps only the assignable types in a union.

type T = Extract<'a' | 'b' | 1, string>; // 'a' | 'b'

9. NonNullable<Type>

Removes null and undefined from Type.

type T = NonNullable<string | null | undefined>; // string

10. Parameters<FunctionType>

Extracts parameter types of a function as a tuple.

type FnParams = Parameters<(x: number, y: string) => void>; // [x: number, y: string]

11. ReturnType<FunctionType>

Extracts the return type of a function.

type FnReturn = ReturnType<() => number>; // number

12. ConstructorParameters<ClassType>

Extracts constructor parameter types as a tuple.

class Cat { constructor(name: string, age: number) {} }
type CatParams = ConstructorParameters<typeof Cat>; // [name: string, age: number]

13. InstanceType<ClassType>

Extracts the instance type of a class constructor.

type CatInstance = InstanceType<typeof Cat>; // Cat

14. ThisParameterType<FunctionType>

Extracts the this parameter type of a function.

function fn(this: { x: number }) {}
type ThisType = ThisParameterType<typeof fn>; // { x: number }

15. OmitThisParameter<FunctionType>

Removes the this parameter from a function type.

type NoThisFn = OmitThisParameter<typeof fn>; // () => void

16. Awaited<Type>

Unwraps Promise return types (useful for async functions).

type T = Awaited<Promise<string>>; // string

17. Uppercase<StringType>

Transforms string literal types to uppercase.

type Greeting = Uppercase<'hello'>; // "HELLO"

18. Lowercase<StringType>

Transforms string literal types to lowercase.

type QuietGreeting = Lowercase<'HELLO'>; // "hello"

19. Capitalize<StringType>

Capitalizes the first letter of a string literal.

type Name = Capitalize<'alice'>; // "Alice"

20. Uncapitalize<StringType>

Uncapitalizes the first letter of a string literal.

type InformalName = Uncapitalize<'Alice'>; // "alice"

Key Takeaways

  1. Transformation Utilities:
  • Modify existing types (Partial, Readonly, Pick, Omit).
  1. Type Extraction:
  • Get function/constructor parameters (Parameters, ConstructorParameters).
  • Extract return types (ReturnType, Awaited).
  1. String Manipulation:
  • Change string literal casing (Uppercase, Capitalize, etc.).
  1. Advanced Use Cases:
  • Record for dictionary types, NonNullable for strict null checks.

Example: Combining Utilities

// Create a read-only subset of an API response
type ApiResponse = {
  id: number;
  name: string;
  email?: string;
};

type SafeResponse = Readonly<Pick<ApiResponse, 'id' | 'name'>>;
// { readonly id: number; readonly name: string }

These utilities help write type-safe, maintainable code with minimal boilerplate.

By davs