{"id":17492402,"url":"https://github.com/kakasoo/deepstricttypes","last_synced_at":"2025-04-22T20:27:47.115Z","repository":{"id":254701419,"uuid":"847292704","full_name":"kakasoo/DeepStrictTypes","owner":"kakasoo","description":"Utility Types to quickly query and Omit, Pick keys inside nested arrays and objects","archived":false,"fork":false,"pushed_at":"2025-03-14T02:40:03.000Z","size":271,"stargazers_count":48,"open_issues_count":5,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-19T03:54:19.894Z","etag":null,"topics":["deep-omit","deep-pick","deep-strict","deep-strict-object-keys","deep-strict-omit","deep-strict-pick","deep-types","nested-types","strict-types","type-assertions","type-checking","type-helpers","type-inference","type-safety","type-utils","type-validation","types","typescript","utility-types"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@kakasoo/deep-strict-types","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kakasoo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-25T12:10:50.000Z","updated_at":"2025-03-27T07:05:17.000Z","dependencies_parsed_at":"2025-01-11T11:29:59.900Z","dependency_job_id":"de77649c-4cd7-4dd0-98eb-cab680c6a483","html_url":"https://github.com/kakasoo/DeepStrictTypes","commit_stats":{"total_commits":11,"total_committers":1,"mean_commits":11.0,"dds":0.0,"last_synced_commit":"6a575bc912613e64bd352f7cd04c99d4b388876b"},"previous_names":["kakasoo/deepstricttypes"],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kakasoo%2FDeepStrictTypes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kakasoo%2FDeepStrictTypes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kakasoo%2FDeepStrictTypes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kakasoo%2FDeepStrictTypes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kakasoo","download_url":"https://codeload.github.com/kakasoo/DeepStrictTypes/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250317976,"owners_count":21410854,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deep-omit","deep-pick","deep-strict","deep-strict-object-keys","deep-strict-omit","deep-strict-pick","deep-types","nested-types","strict-types","type-assertions","type-checking","type-helpers","type-inference","type-safety","type-utils","type-validation","types","typescript","utility-types"],"created_at":"2024-10-19T09:04:15.367Z","updated_at":"2025-04-22T20:27:47.108Z","avatar_url":"https://github.com/kakasoo.png","language":"TypeScript","readme":"# DeepStrictTypes Library Documentation\n\n- [한국어 설명](./docs/README_KO.md)\n\n## Table of Contents\n\n1. [Introduction](#introduction)\n2. [DeepStrictObjectKeys](#deepstrictobjectkeys)\n3. [DeepStrictOmit](#deepstrictomit)\n4. [DeepStrictPick](#deepstrictpick)\n5. [StringToDeepObject](#stringtodeepobject)\n6. [DeepStrictMerge](#deepstrictmerge)\n7. [DeepDateToString](#deepdatetostring)\n\n## Introduction\n\nDeepStrictTypes is a tool that takes TypeScript’s type manipulation to the next level.  \nIt helps you safely perform tasks like `Omit` and `Pick` even with complex nested objects or arrays.  \nBy addressing the limitations of TypeScript’s built-in utility types, it allows you to easily handle internal keys with strict and precise type inference.\n\nKey features include:\n\n- **Safe Nested Key Extraction:** It extracts all keys from within an object, boosting type safety.\n- **Precise Type Manipulation:** You can pick or omit only the keys you need even in deeply nested structures, making it easier to work with complex data.\n- **Unbranding and Merging:** It removes unnecessary constraints from branded types and safely merges multiple types.\n- **Utility Function Support (Experimental):** It even provides runtime functions to further ensure type safety during development.\n\nBelow is a GIF showing an example of how to use the library.\n\n![example](https://github.com/user-attachments/assets/28316425-8302-453e-b238-0c732606e6a7)\n\n## DeepStrictObjectKeys\n\n`DeepStrictObjectKeys` extracts all keys from a nested object, preserving its hierarchical structure as a union of string paths.  \nThat means you can access not only top-level keys but also nested keys using dot notation or, for arrays, using `[*]`.\n\n### Key Features\n\n- **Preserves Hierarchy:** It retrieves every key from within an object so you can express paths like \"user.address.city\".\n- **Accurate Type Inference:** Instead of just using `keyof`, it thoroughly infers every nested key for enhanced type safety.\n- **Array Support:** For objects within arrays, it uses `[*]` instead of an index, so you cover all elements at once.\n\n### Example\n\nThe following example shows how to extract keys from a nested object using `DeepStrictObjectKeys`.\n\n```typescript\ntype Example = {\n  user: {\n    name: string;\n    address: {\n      city: string;\n      zip: number;\n    };\n  };\n};\n\n// Result: \"user\" | \"user.name\" | \"user.address\" | \"user.address.city\" | \"user.address.zip\"\ntype Keys = DeepStrictObjectKeys\u003cExample\u003e;\n```\n\nThe library also offers a utility function `deepStrictObjectKeys` based on this type, which works like `Object.keys` but correctly extracts nested paths.\n\n```typescript\ntype Target = { a: 1 }[][];\nconst keys = deepStrictObjectKeys({} as Target); // Result: [\"[*].[*].a\"]\n```\n\n## DeepStrictOmit\n\n`DeepStrictOmit` creates a new type by removing specified keys from a nested object type.\nSimilar to the built-in `Omit`, it lets you precisely specify key paths—even in nested structures and arrays—to remove unwanted properties.\n\n### Key Features\n\n- **Omit Nested Keys:** You can specify a nested key path like `\"user.profile.name\"` to remove just that property.\n- **Handles Arrays:** It applies the same logic to objects within arrays, so you can remove a key from every element.\n- **Accurate Type Inference:** It preserves the rest of the object’s structure and types after omission.\n- **Supports Branded Types:** It works safely with branded types, removing unnecessary constraints.\n\n### Example\n\nBelow is an example of how to apply `DeepStrictOmit` to both nested objects and objects within arrays.\n\n```typescript\n// Define an example object type\ntype Example = {\n  user: {\n    id: string;\n    profile: {\n      name: string;\n      age: number;\n      email: string;\n    };\n    posts: {\n      title: string;\n      content: string;\n      meta: {\n        likes: number;\n        shares: number;\n      };\n    }[];\n  };\n};\n\n// Remove the keys 'user.profile.email' and 'user.posts[*].meta.shares'\ntype Omitted = DeepStrictOmit\u003cExample, 'user.profile.email' | 'user.posts[*].meta.shares'\u003e;\n\n/*\n  Resulting type Omitted:\n  {\n    user: {\n      id: string;\n      profile: {\n        name: string;\n        age: number;\n      };\n      posts: {\n        title: string;\n        content: string;\n        meta: {\n          likes: number;\n        };\n      }[];\n    };\n  }\n*/\n```\n\nIn short, with `DeepStrictOmit` you can neatly remove only the keys you want from even the most complex nested objects or arrays.\n\n## DeepStrictPick\n\n`DeepStrictPick` creates a new type by selecting only the specified keys from a nested object type.\nIt 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.\n\n### Key Features\n\n- **Pick Nested Keys:** Specify a nested key path like `\"user.profile.name\"` to pick only that property.\n- **Handles Arrays:** It also works on objects within arrays, allowing you to extract just the desired data.\n- **Accurate Type Inference:** It builds a type that only includes the selected properties, enhancing both type safety and readability.\n- **Flexible:** You can specify multiple nested keys at once.\n\n### Example\n\nBelow is an example of using `DeepStrictPick` on nested objects and arrays.\n\n```typescript\n// Define an example object type\ntype Example = {\n  user: {\n    id: string;\n    profile: {\n      name: string;\n      age: number;\n      email: string;\n    };\n    posts: {\n      title: string;\n      content: string;\n      meta: {\n        likes: number;\n        shares: number;\n      };\n    }[];\n  };\n};\n\n// Pick only the keys 'user.profile.name' and 'user.posts[*].meta.likes'\ntype Picked = DeepStrictPick\u003cExample, 'user.profile.name' | 'user.posts[*].meta.likes'\u003e;\n\n/*\n  Resulting type Picked:\n  {\n    user: {\n      profile: {\n        name: string;\n      };\n      posts: {\n        meta: {\n          likes: number;\n        };\n      }[];\n    };\n  }\n*/\n```\n\nSo, `DeepStrictPick` lets you extract only the properties you want from even the most deeply nested structures.\n\n## StringToDeepObject\n\n`StringToDeepObject` takes a string path in dot notation and generates a nested object type corresponding to that path.\nIt parses the path string step by step, building a nested object and assigning the desired type to the final property.\n\n### Key Features\n\n- **Parses Path Strings:** Converts a string like \"user.profile.name\" into an object where each segment becomes a key.\n- **Dynamically Creates Objects:** Automatically builds a nested object based on the path, assigning the specified type at the end.\n- **Merges Union Types:** If you pass a union of path strings, it merges the resulting objects into one combined type.\n- **Type Safe:** Handles string paths safely within the type system to accurately represent nested structures.\n\n### Example\n\n```typescript\n// Example: Assigning a string type to the path 'user.profile.name'\ntype DeepObj = StringToDeepObject\u003c'user.profile.name', string\u003e;\n\n/*\n  Resulting type DeepObj:\n  {\n    user: {\n      profile: {\n        name: string;\n      };\n    };\n  }\n*/\n\n// Another example: Assigning a number type at the end of a path\ntype DeepNumberObj = StringToDeepObject\u003c'settings.display.brightness', number\u003e;\n\n/*\n  Resulting type DeepNumberObj:\n  {\n    settings: {\n      display: {\n        brightness: number;\n      };\n    };\n  }\n*/\n\n// Union type example: Two paths merge into one combined object type\ntype MergedObj = StringToDeepObject\u003c'user.profile.name' | 'user.profile.age', string | number\u003e;\n\n/*\n  Resulting type MergedObj:\n  {\n    user: {\n      profile: {\n        name: string;\n        age: number;\n      };\n    };\n  }\n*/\n```\n\nIn short, `StringToDeepObject` lets you quickly create nested object types from a dot-delimited string, and even merge multiple paths if needed.\n\n## DeepStrictMerge\n\n`DeepStrictMerge` deeply merges two or more object types into a single unified type.\nIt 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.\n\n### Key Features\n\n- **Deep Merge:** Recursively merges not only top-level properties but also all nested objects.\n- **Accurate Type Inference:** Each object’s type information is retained in the merged result, ensuring type safety.\n- **Conflict Resolution:** When the same key exists in multiple objects, it resolves the conflict according to defined rules.\n- **Flexible:** You can merge several object types at once, making it easy to manage complex data structures.\n\n### Example\n\n```typescript\n// Define two object types to merge\ntype ObjA = {\n  user: {\n    id: string;\n    profile: {\n      name: string;\n      age: number;\n    };\n  };\n};\n\ntype ObjB = {\n  user: {\n    profile: {\n      email: string;\n      // If both objects have the key 'age', the merge rule applies.\n      age: number;\n    };\n    settings: {\n      theme: string;\n    };\n  };\n};\n\n// Deep merge the two objects into one type\ntype Merged = DeepStrictMerge\u003cObjA, ObjB\u003e;\n\n/*\n  Resulting type Merged:\n  {\n    user: {\n      id: string;\n      profile: {\n        name: string;\n        age: number;  // Merged according to the rules\n        email: string;\n      };\n      settings: {\n        theme: string;\n      };\n    };\n  }\n*/\n```\n\nSo, `DeepStrictMerge` lets you seamlessly combine different object types into one, even when they have complex nested structures.\n\n## DeepDateToString\n\n`DeepDateToString` finds every `Date` type in an object and converts it to a `string` recursively.\nIt 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.\n\n### Key Features\n\n- **Recursive Conversion:** It transforms every `Date` type found in the object, including those in nested objects and arrays.\n- **Ensures Type Consistency:** By explicitly converting `Date` to `string`, it prevents type mismatches during serialization or API responses.\n- **Handles Complex Structures:** Works reliably even with deeply nested objects and arrays containing `Date` values.\n\n### Example\n\n```typescript\n// Define an example object type\ntype Example = {\n  createdAt: Date;\n  updatedAt: Date;\n  user: {\n    name: string;\n    birthDate: Date;\n    posts: {\n      title: string;\n      publishedAt: Date;\n    }[];\n  };\n};\n\n// Convert all Date properties to string using DeepDateToString\ntype StringifiedExample = DeepDateToString\u003cExample\u003e;\n\n/*\n  Resulting type StringifiedExample:\n  {\n    createdAt: string;\n    updatedAt: string;\n    user: {\n      name: string;\n      birthDate: string;\n      posts: {\n        title: string;\n        publishedAt: string;\n      }[];\n    };\n  }\n*/\n```\n\nIn 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.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkakasoo%2Fdeepstricttypes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkakasoo%2Fdeepstricttypes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkakasoo%2Fdeepstricttypes/lists"}