TypeScript Utility Types
A comprehensive collection of utility types to enhance productivity and improve code readability in TypeScript projects.
TypeScript Utility Types
A powerful collection of utility types designed to enhance your TypeScript development experience. This package provides type-level operations for arrays, objects, strings, numbers, validation, and advanced deep manipulations, all built from scratch without relying on TypeScript's built-in utility types.
All utility types are zero-runtime and provide excellent IntelliSense support with comprehensive type checking.
Features
- ๐ง Comprehensive Type Operations: Over 100+ utility types for common and advanced use cases
- ๐ฏ Type-Safe: All utilities are fully type-safe with excellent IntelliSense support
- ๐ฆ Modular: Import only what you need with tree-shakable exports
- ๐ Zero Runtime: Pure TypeScript types with no runtime overhead
- ๐งช Well-Tested: Extensively tested with type-level assertions
- ๐ Excellent DX: Comprehensive documentation with practical examples
Installation
npm i -D @halvaradop/ts-utility-types
Quick Start
Install the package as a development dependency in your TypeScript project.
Import the types you need from the appropriate module:
import type { DeepMerge } from "@halvaradop/ts-utility-types/deep"
import type { ArrayToUnion } from "@halvaradop/ts-utility-types/arrays"
import type { Capitalize } from "@halvaradop/ts-utility-types/strings"
import { isObject, isArray } from "@halvaradop/ts-utility-types/validate"
Use the types in your TypeScript code:
import type { DeepMerge } from "@halvaradop/ts-utility-types"
interface Config {
api: {
timeout: number
}
features: {
darkMode: boolean
}
}
interface UserConfig {
api: {
retries: number
}
features: {
analytics: boolean
}
}
type AppConfig = DeepMerge<Config, UserConfig>
Available Modules
Arrays
Array and tuple manipulations with type-safe operations
Objects
Object type transformations and property manipulations
Strings
String type operations and template literal utilities
Numbers
Numeric type utilities and mathematical operations
Deep
Advanced deep object manipulations and nested operations
Type Guards
Type checking utilities and conditional type helpers
Validation
Runtime type validation with type guards
Testing
Type-level testing utilities for type assertions
Utils
General utilities and helper types
Common Usage Patterns
Conditional Types
import type { IsArray, IsObject } from "@halvaradop/ts-utility-types/type-guards"
type ProcessData<T> =
IsArray<T> extends true
? T[number] // Extract array element type
: IsObject<T> extends true
? keyof T // Extract object keys
: T // Return as-is for primitives
Advanced Object Manipulation
import type { DeepPartial, DeepRequired, DeepReadonly } from "@halvaradop/ts-utility-types/deep"
interface ApiResponse {
user: {
profile: { name: string; email: string }
settings: { theme: string; notifications: boolean }
}
}
type PartialApiResponse = DeepPartial<ApiResponse>
type RequiredApiResponse = DeepRequired<PartialApiResponse>
type ImmutableApiResponse = DeepReadonly<ApiResponse>
Performance Note
All utility types are designed to be efficient at compile-time with recursive depth limits and tail recursion optimization where possible.
TypeScript Compatibility
- TypeScript 4.5+: Core functionality
- TypeScript 4.8+: Improved template literal types
- TypeScript 5.0+: Enhanced recursive type handling
Need Help?
Visit our Community & Support page to:
- ๐ Report bugs or request features
- ๐ฌ Join community discussions
- ๐ค Learn how to contribute
- ๐ Find additional resources
Ready to get started? Choose a module from the navigation or explore the Arrays section for practical examples.