Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,12 @@ export interface InternalHooks {

/** Only return partial when type is not any */
type RecursivePartial<T> =
NonNullable<T> extends object
? {
[P in keyof T]?: NonNullable<T[P]> extends (infer U)[]
? RecursivePartial<U>[]
: NonNullable<T[P]> extends object
? RecursivePartial<T[P]>
: T[P];
}
T extends (infer U)[]
Comment thread
QDyanbing marked this conversation as resolved.
? RecursivePartial<U>[]
: T extends object
? {
[P in keyof T]?: RecursivePartial<T[P]>;
}
: T;

export type FilterFunc = (meta: Meta | null) => boolean;
Expand Down
25 changes: 24 additions & 1 deletion tests/nameTypeCheck.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React, { useMemo } from 'react';
import { render } from '@testing-library/react';
import Form, { Field, List } from '../src';
import type { NamePath } from '../src/interface';
import type { FormInstance, NamePath } from '../src/interface';

describe('nameTypeCheck', () => {
it('typescript', () => {
Expand All @@ -13,10 +13,33 @@ describe('nameTypeCheck', () => {
d?: { d1?: string[]; d2?: string };
e?: { e1?: { e2?: string; e3?: string[]; e4: { e5: { e6: string } } } };
list?: { age?: string }[];
strictList?: { age: string; name: string }[];
user?: { profile: { name: string; tags: string[] } };
nullableList?: string[] | null;
nullableObjectList?: { name?: string }[] | null;
};

type fieldType = NamePath<FieldType>;

type SetFieldsValueParam = Parameters<FormInstance<FieldType>['setFieldsValue']>[0];

const nullableListAsNull: SetFieldsValueParam = { nullableList: null };
const nullableListAsArray: SetFieldsValueParam = { nullableList: ['bamboo'] };
const nullableObjectListAsNull: SetFieldsValueParam = { nullableObjectList: null };
const nullableObjectListAsArray: SetFieldsValueParam = {
nullableObjectList: [{ name: 'light' }],
};
const optionalNestedObjectAsPartial: SetFieldsValueParam = {
user: {
profile: {
name: 'light',
},
},
};
const optionalListAsPartial: SetFieldsValueParam = {
strictList: [{ age: '18' }],
};

const Demo: React.FC = () => {
return (
<Form>
Expand Down
Loading