Skip to content

Commit

Permalink
feat: 支持 bool
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyair committed Jul 29, 2023
1 parent 4c6e5cf commit 0ee359b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/namePathType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export type DeepNamePathBase<Store = any, ParentNamePath extends any[] = []> =
:
| (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)[]
| (Store[FieldKey] extends (number | string | boolean)[]
? [...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
Expand Down
4 changes: 3 additions & 1 deletion tests/nameTypeCheck.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('nameTypeCheck', () => {
type FieldType = {
a: string;
b?: string[];
c?: { c1?: string; c2?: string[] }[];
c?: { c1?: string; c2?: string[]; c3?: boolean[] }[];
d?: { d1?: string[]; d2?: string };
e?: { e1?: { e2?: string; e3?: string[]; e4: { e5: { e6: string } } } };
list?: { age?: string }[];
Expand Down Expand Up @@ -45,6 +45,8 @@ describe('nameTypeCheck', () => {
<Field<FieldType> name={['c', 1, 'c1']} />
<Field<FieldType> name={['c', 1, 'c2']} />
<Field<FieldType> name={['c', 1, 'c2', 1]} />
<Field<FieldType> name={['c', 1, 'c3']} />
<Field<FieldType> name={['c', 1, 'c3', 1]} />
<Field<FieldType> name={['d', 'd1']} />
<Field<FieldType> name={['d', 'd1', 1]} />
<Field<FieldType> name={['d', 'd2']} />
Expand Down

0 comments on commit 0ee359b

Please sign in to comment.