Skip to content

Commit

Permalink
feat: 过滤方法
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyair committed Jul 29, 2023
1 parent 173dd7a commit 4c6e5cf
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/namePathType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ export type DeepNamePathBase<Store = any, ParentNamePath extends any[] = []> =
: Store extends Record<string, any> // Check if `Store` is `object`
? {
// Convert `Store` to <key, value>. We mark key a `FieldKey`
[FieldKey in keyof Store]:
| (ParentNamePath['length'] extends 0 ? FieldKey : never) // If `ParentNamePath` is empty, it can use `FieldKey` without array path
| [...ParentNamePath, FieldKey] // Exist `ParentNamePath`, connect it
| (Store[FieldKey] extends (number | string)[]
? [...ParentNamePath, FieldKey, number] // If `Store[FieldKey]` is base array type
: Store[FieldKey] extends Record<string, any>
? DeepNamePathBase<Store[FieldKey], [...ParentNamePath, FieldKey]> // If `Store[FieldKey]` is object
: never);
[FieldKey in keyof Store]: Store[FieldKey] extends (...p: any) => any // Filter function
? never
:
| (ParentNamePath['length'] extends 0 ? FieldKey : never) // If `ParentNamePath` is empty, it can use `FieldKey` without array path
| [...ParentNamePath, FieldKey] // Exist `ParentNamePath`, connect it
| (Store[FieldKey] extends (number | string)[]
? [...ParentNamePath, FieldKey, number] // If `Store[FieldKey]` is base array type
: Store[FieldKey] extends Record<string, any>
? DeepNamePathBase<Store[FieldKey], [...ParentNamePath, FieldKey]> // If `Store[FieldKey]` is object
: never);
}[keyof Store]
: never;

Expand Down

0 comments on commit 4c6e5cf

Please sign in to comment.