Skip to content

Commit

Permalink
Revert "⌨️ fix #10734 watch and useWatch without parameters return ty…
Browse files Browse the repository at this point in the history
…pe (#11359)"

This reverts commit fdbadbb.
  • Loading branch information
bluebill1049 committed Feb 6, 2024
1 parent 5c3b4c0 commit 7cffc95
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 25 deletions.
12 changes: 3 additions & 9 deletions reports/api-extractor.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,6 @@ export type NonUndefined<T> = T extends undefined ? never : T;
// @public (undocumented)
export type Noop = () => void;

// @public (undocumented)
export type PartialFormValues<TFieldValues extends FieldValues> = DeepPartialSkipArrayKey<TFieldValues>;

// Warning: (ae-forgotten-export) The symbol "PathInternal" needs to be exported by the entry point index.d.ts
//
// @public
Expand Down Expand Up @@ -782,7 +779,7 @@ export type UseFormUnregister<TFieldValues extends FieldValues> = (name?: FieldP

// @public (undocumented)
export type UseFormWatch<TFieldValues extends FieldValues> = {
(): WatchedForm<TFieldValues>;
(): TFieldValues;
<TFieldNames extends readonly FieldPath<TFieldValues>[]>(names: readonly [...TFieldNames], defaultValue?: DeepPartial<TFieldValues>): FieldPathValues<TFieldValues, TFieldNames>;
<TFieldName extends FieldPath<TFieldValues>>(name: TFieldName, defaultValue?: FieldPathValue<TFieldValues, TFieldName>): FieldPathValue<TFieldValues, TFieldName>;
(callback: WatchObserver<TFieldValues>, defaultValues?: DeepPartial<TFieldValues>): Subscription;
Expand All @@ -794,7 +791,7 @@ export function useWatch<TFieldValues extends FieldValues = FieldValues>(props:
control?: Control<TFieldValues>;
disabled?: boolean;
exact?: boolean;
}): WatchedForm<TFieldValues>;
}): DeepPartialSkipArrayKey<TFieldValues>;

// @public
export function useWatch<TFieldValues extends FieldValues = FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>(props: {
Expand Down Expand Up @@ -858,9 +855,6 @@ export type ValidationValueMessage<TValidationValue extends ValidationValue = Va
message: Message;
};

// @public (undocumented)
export type WatchedForm<TFieldValues extends FieldValues> = PartialFormValues<TFieldValues>;

// @public (undocumented)
export type WatchInternal<TFieldValues> = (fieldNames?: InternalFieldName | InternalFieldName[], defaultValue?: DeepPartial<TFieldValues>, isMounted?: boolean, isGlobal?: boolean) => FieldPathValue<FieldValues, InternalFieldName> | FieldPathValues<FieldValues, InternalFieldName[]>;

Expand All @@ -872,7 +866,7 @@ export type WatchObserver<TFieldValues extends FieldValues> = (value: DeepPartia

// Warnings were encountered during analysis:
//
// src/types/form.ts:446:3 - (ae-forgotten-export) The symbol "Subscription" needs to be exported by the entry point index.d.ts
// src/types/form.ts:440:3 - (ae-forgotten-export) The symbol "Subscription" needs to be exported by the entry point index.d.ts

// (No @packageDocumentation comment for this package)

Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/controller.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '@testing-library/react';

import { Controller } from '../controller';
import { ControllerRenderProps, FieldValues, WatchedForm } from '../types';
import { ControllerRenderProps, FieldValues } from '../types';
import { useFieldArray } from '../useFieldArray';
import { useForm } from '../useForm';
import { FormProvider } from '../useFormContext';
Expand Down Expand Up @@ -983,7 +983,7 @@ describe('Controller', () => {
type FormValue = {
test: string;
};
const watchedValue: WatchedForm<FormValue>[] = [];
const watchedValue: FormValue[] = [];
const Component = () => {
const { control, watch } = useForm<FormValue>({
defaultValues: {
Expand Down
3 changes: 1 addition & 2 deletions src/__tests__/useFieldArray.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
SubmitHandler,
UseFormRegister,
UseFormReturn,
WatchedForm,
} from '../types';
import { useFieldArray } from '../useFieldArray';
import { useForm } from '../useForm';
Expand Down Expand Up @@ -2696,7 +2695,7 @@ describe('useFieldArray', () => {
}[];
};

const watchedValues: WatchedForm<FormValues>[] = [];
const watchedValues: FormValues[] = [];

const Child = ({
control,
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/useForm/register.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { act, renderHook } from '@testing-library/react-hooks';

import { VALIDATION_MODE } from '../../constants';
import { Controller } from '../../controller';
import { UseFormRegister, WatchedForm } from '../../types';
import { UseFormRegister } from '../../types';
import { useForm } from '../../useForm';
import { FormProvider, useFormContext } from '../../useFormContext';
import isFunction from '../../utils/isFunction';
Expand Down Expand Up @@ -479,7 +479,7 @@ describe('register', () => {
type FormValue = {
test: string;
};
const watchedValue: WatchedForm<FormValue>[] = [];
const watchedValue: FormValue[] = [];
const Component = () => {
const { register, watch } = useForm<FormValue>({
defaultValues: {
Expand Down
10 changes: 2 additions & 8 deletions src/types/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
FieldPathValues,
} from './path';
import { Resolver } from './resolvers';
import { DeepMap, DeepPartial, DeepPartialSkipArrayKey, Noop } from './utils';
import { DeepMap, DeepPartial, Noop } from './utils';
import { RegisterOptions } from './validator';

declare const $NestedValue: unique symbol;
Expand All @@ -44,12 +44,6 @@ export type UnpackNestedValue<T> = T extends NestedValue<infer U>
? { [K in keyof T]: UnpackNestedValue<T[K]> }
: T;

export type PartialFormValues<TFieldValues extends FieldValues> =
DeepPartialSkipArrayKey<TFieldValues>;

export type WatchedForm<TFieldValues extends FieldValues> =
PartialFormValues<TFieldValues>;

export type DefaultValues<TFieldValues> =
TFieldValues extends AsyncDefaultValues<TFieldValues>
? DeepPartial<Awaited<TFieldValues>>
Expand Down Expand Up @@ -381,7 +375,7 @@ export type UseFormWatch<TFieldValues extends FieldValues> = {
* const formValues = watch();
* ```
*/
(): WatchedForm<TFieldValues>;
(): TFieldValues;
/**
* Watch and subscribe to an array of fields used outside of render.
*
Expand Down
3 changes: 1 addition & 2 deletions src/useWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
FieldValues,
InternalFieldName,
UseWatchProps,
WatchedForm,
} from './types';
import { useFormContext } from './useFormContext';
import { useSubscribe } from './useSubscribe';
Expand Down Expand Up @@ -45,7 +44,7 @@ export function useWatch<
control?: Control<TFieldValues>;
disabled?: boolean;
exact?: boolean;
}): WatchedForm<TFieldValues>;
}): DeepPartialSkipArrayKey<TFieldValues>;
/**
* Custom hook to subscribe to field change and isolate re-rendering at the component level.
*
Expand Down

0 comments on commit 7cffc95

Please sign in to comment.