Skip to content

Commit

Permalink
⌨️ fix react-hook-form#3363 UnpackNestedValue with extends primitive (r…
Browse files Browse the repository at this point in the history
…eact-hook-form#3375)

* fix react-hook-form#3363 UnpackNestedValue with extends primitive

* fix actual issue

* remove expect error
  • Loading branch information
bluebill1049 authored Nov 6, 2020
1 parent 4c660f8 commit 4724749
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
15 changes: 8 additions & 7 deletions src/types/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,15 @@ export type UseFormMethods<TFieldValues extends FieldValues = FieldValues> = {
): UnpackNestedValue<DeepPartial<TFieldValues>>;
setError(name: FieldName<TFieldValues>, error: ErrorOption): void;
clearErrors(name?: FieldName<TFieldValues> | FieldName<TFieldValues>[]): void;
setValue<
TFieldName extends string,
TFieldValue extends TFieldValues[TFieldName]
>(
setValue<TFieldName extends string>(
name: TFieldName,
value: TFieldValue extends NestedValue<infer U>
? U
: UnpackNestedValue<DeepPartial<LiteralToPrimitive<TFieldValue>>>,
value:
| FieldValue<TFieldValues>
| UnpackNestedValue<DeepPartial<TFieldValues>>
| string[]
| undefined
| null
| boolean,
options?: SetValueConfig,
): void;
trigger(
Expand Down
2 changes: 0 additions & 2 deletions src/useForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -724,12 +724,10 @@ describe('useForm', () => {

result.current.register(elm);

// @ts-expect-error
result.current.setValue('test', null);

expect(elm).not.toHaveValue();

// @ts-expect-error
result.current.setValue('test', undefined);

expect(elm).not.toHaveValue();
Expand Down

0 comments on commit 4724749

Please sign in to comment.