feat(typescript-types): Fully rewrite KeyPaths<T,O,F>
Again to solve 'Too deep instantiation', but this time using tail recursion optimization on conditions.
This commit is contained in:
@@ -4,6 +4,7 @@ import type { And } from './and.js'
|
||||
import type { Not } from './not.js'
|
||||
import type { IsEmptyString } from './is-empty-string.js'
|
||||
import type { Extends } from './extends.js'
|
||||
import type { ExtendsExactly } from './extends-exactly.js'
|
||||
import type { Concat } from './concat.js'
|
||||
import type { Assign } from './assign.js'
|
||||
import type { NonContainerType } from './non-container-type.js'
|
||||
@@ -22,8 +23,18 @@ interface KeyPaths_DefaultOptions {
|
||||
invertFilter: false
|
||||
}
|
||||
|
||||
type ExtendsFilter<Obj, Key extends keyof Obj, Filter> =
|
||||
Extends<Obj[Key], Filter> extends false ? false : true
|
||||
type ExtendsFilter<
|
||||
Obj,
|
||||
Key extends keyof Obj,
|
||||
Filter,
|
||||
MatchExactly extends boolean = false
|
||||
> = MatchExactly extends false
|
||||
? Extends<Obj[Key], Filter> extends false
|
||||
? false
|
||||
: true
|
||||
: ExtendsExactly<Obj[Key], Filter> extends false
|
||||
? false
|
||||
: true
|
||||
|
||||
type IncludeElement<Obj, Key extends keyof Obj, Filter, Options extends RequiredOptions> = Obj extends never
|
||||
? false
|
||||
@@ -33,10 +44,16 @@ type IncludeElement<Obj, Key extends keyof Obj, Filter, Options extends Required
|
||||
? false
|
||||
: Not<
|
||||
Or<
|
||||
And<ExtendsFilter<Obj, Key, Filter>, Not<Options['invertFilter']>>,
|
||||
And<
|
||||
And<Not<ExtendsFilter<Obj, Key, Filter>>, Options['invertFilter']>,
|
||||
Not<Obj[Key] extends object ? true : false>
|
||||
ExtendsFilter<Obj, Key, Filter, Options['invertFilter']>,
|
||||
Not<Options['invertFilter']>
|
||||
>,
|
||||
And<
|
||||
And<
|
||||
Not<ExtendsFilter<Obj, Key, Filter, Options['invertFilter']>>,
|
||||
Options['invertFilter']
|
||||
>,
|
||||
Not<Obj[Key] extends object | any[] ? true : false>
|
||||
>
|
||||
>
|
||||
>
|
||||
@@ -80,4 +97,5 @@ export type KeyPaths<
|
||||
Obj,
|
||||
Options extends KeyPaths_Options = {},
|
||||
Filter = null | undefined
|
||||
> = KeyPathsOfStringKeys<Obj, keyof Obj, Assign<KeyPaths_Options, KeyPaths_DefaultOptions, Options>, Filter>
|
||||
> = KeyPathsOfStringKeys<Obj, keyof Obj, Assign<KeyPaths_Options, KeyPaths_DefaultOptions, Options>, Filter> &
|
||||
string
|
||||
|
||||
Reference in New Issue
Block a user