Skip to content

phryneas/ts-deep-extract-types

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published