Deep Flatten Type Utility is a lightweight TypeScript utility that flattens deeply nested object types into a dot-separated union of keys. All optional keys are treated as required, ensuring flexibility and consistency.
Install via npm or yarn:
npm install deep-flatten-type
# or
yarn add deep-flatten-type
- TypeScript-First: Define and manipulate deeply nested object types with ease.
- Dot-Separated Union: Automatically flattens keys into a dot-separated union.
- Supports Optional Keys: Treats all optional keys as required.
Here's an example of how to use DeepFlatten
:
import { DeepFlatten } from "deep-flatten-type";
type NestedObject = {
a: {
b: {
c: number;
};
d: string;
};
e: boolean;
};
const paths: DeepFlatten<NestedObject> = "e" | "a.d" | "a.b.c";
Given the type NestedObject
, DeepFlatten<NestedObject>
generates a union of string paths representing all possible keys:
"e"
"a.d"
"a.b.c"
T
: The deeply nested object type to be flattened.
Returns: A union of dot-separated string paths for all keys in T
.
Contributions are welcome! If you encounter any issues or have feature requests, feel free to open an issue or submit a pull request on GitHub.
This project is licensed under the MIT License.