ts-deep-extract-types
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i ts-deep-extract-types

Weekly Downloads

803

Version

1.0.1

License

MIT

Unpacked Size

3.65 kB

Total Files

4

Last publish

Collaborators

  • phryneas