advanced-utility-types
raw JSON → 1.1.0 verified Fri May 01 auth: no javascript
A TypeScript library providing advanced utility generic types such as DeepOptional, DeepOmit, and DeepPaths. Version 1.1.0 allows recursive manipulation of deeply nested object properties using dot-separated paths or template literal strings, with support for arrays. It is released under the MIT license and is intended for type-level programming in TypeScript projects. Unlike simpler utility types libraries (e.g., type-fest), this package focuses specifically on deep path-based transformations.
Common errors
error Type instantiation is excessively deep and possibly infinite. ↓
cause DeepPaths or related recursive types applied to a deeply nested object type.
fix
Reduce nesting depth or use explicit path strings instead of DeepPaths.
error Cannot find name 'DeepOptional'. Did you mean 'Optional'? ↓
cause Incorrect import path or library not installed.
fix
Install the package: npm install advanced-utility-types, then import as named export.
error Type 'string' is not assignable to type '${number}'. ↓
cause Using a plain string literal instead of a template literal type for array indices.
fix
Use a template literal:
a.b.${number}.c instead of a.b.number.c. Warnings
breaking TypeScript version requirement: The library uses template literal types, requiring TypeScript 4.1 or later. ↓
fix Upgrade TypeScript to at least version 4.1.
breaking DeepPaths may generate very large union types for deeply nested objects, leading to performance issues or TypeScript compilation errors. ↓
fix Limit the depth of nested types or use alternative types with manual path specification.
gotcha DeepOptional does not deeply preserve required properties for array items; only the specified path is made optional. ↓
fix When using array paths like `a.b.${number}.c`, only the leaf property (c) becomes optional, not the array indices.
gotcha DeepOmit will remove the property entirely; if the object becomes empty (e.g., all properties omitted), the type reduces to {}. ↓
fix Ensure that after omission, the resulting type still matches your expected shape; consider using DeepOptional instead.
Install
npm install advanced-utility-types yarn add advanced-utility-types pnpm add advanced-utility-types Imports
- DeepOptional wrong
const { DeepOptional } = require('advanced-utility-types')correctimport { DeepOptional } from 'advanced-utility-types' - DeepOmit wrong
import DeepOmit from 'advanced-utility-types'correctimport { DeepOmit } from 'advanced-utility-types' - DeepPaths wrong
import { DeepPaths } from 'advanced-utility-types/types'correctimport { DeepPaths } from 'advanced-utility-types'
Quickstart
import { DeepOptional, DeepOmit, DeepPaths } from 'advanced-utility-types';
type Obj = {
a: string;
b: {
c: number;
d: {
e: boolean;
}
};
f: Array<{ g: string; h: number }>;
};
// DeepOptional: make a deeply nested property optional
type OptionalResult = DeepOptional<Obj, 'b.d.e'>;
// Expected: { a: string; b: { c: number; d: { e?: boolean } }; f: Array<{ g: string; h: number }> }
// DeepOmit: remove a deeply nested property
type OmitResult = DeepOmit<Obj, 'b.d.e'>;
// Expected: { a: string; b: { c: number; d: {} }; f: Array<{ g: string; h: number }> }
// DeepPaths: get all dot-separated paths
type Paths = DeepPaths<Obj>;
// Expected: 'a' | 'b' | 'b.c' | 'b.d' | 'b.d.e' | 'f' | `f.${number}` | `f.${number}.g` | `f.${number}.h`
// Array support with template literals
type ArrObj = { a: { b: Array<{ c: string }> } };
type Result = DeepOptional<ArrObj, `a.b.${number}.c`>;
// Expected: { a: { b: Array<{ c?: string }> } }