ts-deep-extract-types
v1.0.1
Published
This packages exposes types that allow you to extract deeply nested types.
Downloads
7,727
Readme
This packages exposes types that allow you to extract deeply nested types.
type DeepExtractTypeSkipArrays<Source, Path extends [...string[]]>
Extracts a deeply-nested type from the target Path
in Source
, skipping arrays and ignoring null|undefined|optional types:
type QueryResult = { allPosts?: Array<{ users?: Array<{ name: string }> }> };
// will be { name: string }
type User = DeepExtractTypeSkipArrays<QueryResult, ["allPosts", "users"]>;
type DeepExtractType<Source, Path extends [...(string | number)[]]>
Extracts a deeply-nested type from the target Path
in Source
, ignoring null|undefined|optional types:
type QueryResult = { user?: { firstPost?: { title: string } } };
// will be { title: string }
type Post = DeepExtractType<QueryResult, ["user", "firstPost"]>;