1.0.1 • Published 4 years ago

ts-deep-extract-types v1.0.1

Weekly downloads
1,001
License
MIT
Repository
github
Last release
4 years ago

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"]>;