
Product
Introducing Custom Pull Request Alert Comment Headers
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
@kakasoo/deep-strict-types
Advanced tools
typescript utility types including deep-strict-omit and pick type
DeepStrictTypes is a tool that takes TypeScript’s type manipulation to the next level.
It helps you safely perform tasks like Omit
and Pick
even with complex nested objects or arrays.
By addressing the limitations of TypeScript’s built-in utility types, it allows you to easily handle internal keys with strict and precise type inference.
Key features include:
Below is a GIF showing an example of how to use the library.
DeepStrictObjectKeys
extracts all keys from a nested object, preserving its hierarchical structure as a union of string paths.
That means you can access not only top-level keys but also nested keys using dot notation or, for arrays, using [*]
.
keyof
, it thoroughly infers every nested key for enhanced type safety.[*]
instead of an index, so you cover all elements at once.The following example shows how to extract keys from a nested object using DeepStrictObjectKeys
.
type Example = {
user: {
name: string;
address: {
city: string;
zip: number;
};
};
};
// Result: "user" | "user.name" | "user.address" | "user.address.city" | "user.address.zip"
type Keys = DeepStrictObjectKeys<Example>;
The library also offers a utility function deepStrictObjectKeys
based on this type, which works like Object.keys
but correctly extracts nested paths.
type Target = { a: 1 }[][];
const keys = deepStrictObjectKeys({} as Target); // Result: ["[*].[*].a"]
DeepStrictOmit
creates a new type by removing specified keys from a nested object type.
Similar to the built-in Omit
, it lets you precisely specify key paths—even in nested structures and arrays—to remove unwanted properties.
"user.profile.name"
to remove just that property.Below is an example of how to apply DeepStrictOmit
to both nested objects and objects within arrays.
// Define an example object type
type Example = {
user: {
id: string;
profile: {
name: string;
age: number;
email: string;
};
posts: {
title: string;
content: string;
meta: {
likes: number;
shares: number;
};
}[];
};
};
// Remove the keys 'user.profile.email' and 'user.posts[*].meta.shares'
type Omitted = DeepStrictOmit<Example, 'user.profile.email' | 'user.posts[*].meta.shares'>;
/*
Resulting type Omitted:
{
user: {
id: string;
profile: {
name: string;
age: number;
};
posts: {
title: string;
content: string;
meta: {
likes: number;
};
}[];
};
}
*/
In short, with DeepStrictOmit
you can neatly remove only the keys you want from even the most complex nested objects or arrays.
DeepStrictPick
creates a new type by selecting only the specified keys from a nested object type.
It works like the built-in Pick
but lets you precisely choose key paths—even in nested structures and arrays—so you only get the properties you need.
"user.profile.name"
to pick only that property.Below is an example of using DeepStrictPick
on nested objects and arrays.
// Define an example object type
type Example = {
user: {
id: string;
profile: {
name: string;
age: number;
email: string;
};
posts: {
title: string;
content: string;
meta: {
likes: number;
shares: number;
};
}[];
};
};
// Pick only the keys 'user.profile.name' and 'user.posts[*].meta.likes'
type Picked = DeepStrictPick<Example, 'user.profile.name' | 'user.posts[*].meta.likes'>;
/*
Resulting type Picked:
{
user: {
profile: {
name: string;
};
posts: {
meta: {
likes: number;
};
}[];
};
}
*/
So, DeepStrictPick
lets you extract only the properties you want from even the most deeply nested structures.
StringToDeepObject
takes a string path in dot notation and generates a nested object type corresponding to that path.
It parses the path string step by step, building a nested object and assigning the desired type to the final property.
// Example: Assigning a string type to the path 'user.profile.name'
type DeepObj = StringToDeepObject<'user.profile.name', string>;
/*
Resulting type DeepObj:
{
user: {
profile: {
name: string;
};
};
}
*/
// Another example: Assigning a number type at the end of a path
type DeepNumberObj = StringToDeepObject<'settings.display.brightness', number>;
/*
Resulting type DeepNumberObj:
{
settings: {
display: {
brightness: number;
};
};
}
*/
// Union type example: Two paths merge into one combined object type
type MergedObj = StringToDeepObject<'user.profile.name' | 'user.profile.age', string | number>;
/*
Resulting type MergedObj:
{
user: {
profile: {
name: string;
age: number;
};
};
}
*/
In short, StringToDeepObject
lets you quickly create nested object types from a dot-delimited string, and even merge multiple paths if needed.
DeepStrictMerge
deeply merges two or more object types into a single unified type.
It recursively combines every property in nested structures, and when the same key exists in multiple objects, it follows a set of rules to merge them.
// Define two object types to merge
type ObjA = {
user: {
id: string;
profile: {
name: string;
age: number;
};
};
};
type ObjB = {
user: {
profile: {
email: string;
// If both objects have the key 'age', the merge rule applies.
age: number;
};
settings: {
theme: string;
};
};
};
// Deep merge the two objects into one type
type Merged = DeepStrictMerge<ObjA, ObjB>;
/*
Resulting type Merged:
{
user: {
id: string;
profile: {
name: string;
age: number; // Merged according to the rules
email: string;
};
settings: {
theme: string;
};
};
}
*/
So, DeepStrictMerge
lets you seamlessly combine different object types into one, even when they have complex nested structures.
DeepDateToString
finds every Date
type in an object and converts it to a string
recursively.
It locates all Date
properties—even deep within nested objects or arrays—and converts them to strings, which is especially useful for serialization or JSON conversion.
Date
type found in the object, including those in nested objects and arrays.Date
to string
, it prevents type mismatches during serialization or API responses.Date
values.// Define an example object type
type Example = {
createdAt: Date;
updatedAt: Date;
user: {
name: string;
birthDate: Date;
posts: {
title: string;
publishedAt: Date;
}[];
};
};
// Convert all Date properties to string using DeepDateToString
type StringifiedExample = DeepDateToString<Example>;
/*
Resulting type StringifiedExample:
{
createdAt: string;
updatedAt: string;
user: {
name: string;
birthDate: string;
posts: {
title: string;
publishedAt: string;
}[];
};
}
*/
In short, DeepDateToString
makes sure that every Date
inside an object is converted to a string
, ensuring type consistency for operations like serialization or JSON conversion.
FAQs
typescript utility types including deep-strict-omit and pick type
The npm package @kakasoo/deep-strict-types receives a total of 131 weekly downloads. As such, @kakasoo/deep-strict-types popularity was classified as not popular.
We found that @kakasoo/deep-strict-types demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.