ts-deep-types
v0.1.0-beta.1
Published
Type-safe utility types for TypeScript. Deep types, string manipulation, function helpers, and React integration.
Maintainers
Readme
ts-deep-types
A comprehensive collection of type-safe utility types for TypeScript.
What It Does
Provides missing TypeScript utility types that should exist in the standard library but don't:
- Deep types — Recursive transformations on nested objects
- String types — Case conversion (camelCase, snake_case, kebab-case)
- Function types — Parameter/return type extraction
- Type guards — Runtime type checking
- Object utilities — Key/value manipulation
Installation
# npm
npm install ts-deep-types
# pnpm
pnpm add ts-deep-types
# yarn
yarn add ts-deep-typesUsage
import { DeepPartial, CamelCase, Parameters, IsAny } from 'ts-deep-types'
// Deep types
type PartialConfig = DeepPartial<{
database: { host: string; port: number }
}>
// { database?: { host?: string; port?: number } | undefined }
// String types
type CamelStr = CamelCase<'hello_world'>
// 'helloWorld'
// Function types
type FnParams = Parameters<(a: string, b: number) => void>
// [string, number]
// Type guards
type TestAny = IsAny<any> // true
type TestNever = IsAny<never> // falseFeatures
Core Types
DeepPartial- Recursive partial typesDeepRequired- Recursive required typesDeepReadonly- Deep readonly for nested objectsPickDeep- Deep pick with nested pathsOmitDeep- Deep omit with nested pathsMerge- Merge two object typesUnionToIntersection- Convert union to intersection
String Types
CamelCase- Convert to camelCaseKebabCase- Convert to kebab-caseSnakeCase- Convert to snake_casePascalCase- Convert to PascalCaseTrim- Trim strings in templates
Function Types
Parameters- Function parametersReturnType- Return typeThisParameterType-thisparameter typeAsyncReturnType- Async version of ReturnType
Type Guards
IsAny- Check if type isanyIsNever- Check if type isneverIsUnknown- Check if type isunknownIsUnion- Check if type is a unionIsTuple- Check if type is a tupleIsArray- Check if type is an arrayIsPlainObject- Check if type is a plain objectIsFunction- Check if type is a functionIsConstructor- Check if type is a constructor
Object Utilities
KeysOfType- Keys matching a typeValueOf- Values of a union typeEntryOf- Key-value entriesRequiredKeys- Keys that are requiredOptionalKeys- Keys that are optionalReadonlyKeys- Keys that are readonlyWritableKeys- Keys that are mutable
Why ts-deep-types?
TypeScript's standard utility types (Partial, Pick, Omit) only work at one level. When you need recursive transformations, you're on your own.
ts-deep-types provides the missing utilities:
// Standard library (one level)
type A = Partial<{ a: { b: { c: string } } }>
// { a?: { b?: { c?: string } } | undefined } | undefined
// ts-deep-types (recursive)
type B = DeepPartial<{ a: { b: { c: string } } }>
// { a?: { b?: { c?: string } } | undefined } | undefined }
// All levels are partial!Development
# Install dependencies
pnpm install
# Run tests
pnpm test
# Build for production
pnpm buildLicense
MIT © Peter W.
Contributing
Issues and PRs welcome!
