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:
@@ -70,8 +70,9 @@ type KeysWithLeavesOnlyDisabled =
|
||||
| 'arrayKey.0.age'
|
||||
| 'arrayKey.1'
|
||||
|
||||
// type T = any extends never ? true : false
|
||||
// type A = KeyPaths<ExampleObject, { invertFilter: true }>
|
||||
type KeysWithStringValuesOnly = 'simplevalue' | 'objectKey.name' | 'arrayKey.0.name'
|
||||
|
||||
// type A = KeyPaths<ExampleObject, { invertFilter: true }, string>
|
||||
expect<KeyPaths<ExampleObject>>().type.toBe<KeysWithDefaultSettings>()
|
||||
expect<KeyPaths<ExampleObject, { invertFilter: true }>>().type.toBe<KeysWithInvertFilterSettings>()
|
||||
expect<KeyPaths<ExampleObject, { separator: '-' }>>().type.toBe<KeysWithSpecialSeparator>()
|
||||
@@ -82,3 +83,4 @@ expect<KeyPaths<ExampleObject, {}, any>>().type.toBeAssignableWith<never>()
|
||||
|
||||
expect<KeyPaths<ExampleObject, { invertFilter: true }, never>>().type.toBeAssignableWith<never>()
|
||||
expect<KeyPaths<ExampleObject, { invertFilter: true }, any>>().type.toBe<KeysWhenFilterIsSetToNever>()
|
||||
expect<KeyPaths<ExampleObject, { invertFilter: true }, string>>().type.toBe<KeysWithStringValuesOnly>()
|
||||
|
||||
Reference in New Issue
Block a user