Open namdq-2825 opened 9 months ago
+1
Yeah, something not right here at all.
Btw downgrade helps for now..
Btw downgrade helps for now..
Yep - unfortunately I went back down to 2.19.11 I think it was.
I was facing the same issue pls give me a accurate answer which library version i can downgrade or upgrade @arminsalcin @OldManMeta
Can you provide a Codesandbox with the issue?
I can solve this issue by this code added to my code
`//import all the statement const { createUniversity } = universityApi.endpoints;
export default function UniversityForm({ currentUniversity, isUpdate, onClose }: UniversityFormProps) {
const { t } = useTranslation();
const dispatch = useDispatch<ThunkDispatch<RootState, undefined, UniversityActionTypes>>();
const defaultValues = useMemo
const methods = useForm
const { updateUniversity, isLoading, error, data } = useUpdateUniversityMutation(); const { alertSuccess, alertError } = useSnackBar();
const { reset, handleSubmit, trigger, watch, formState: { isSubmitting }, } = methods;
const values = watch();
useEffect(() => { if (isUpdate && currentUniversity) { reset(defaultValues); } if (!isUpdate) { reset(defaultValues); } }, [isUpdate, currentUniversity]);
const onSubmit = async () => { if (!isUpdate) { create(); } else { update(); } };
const create = async () => { try { trigger().then(async (isValid) => { if (isValid) { dispatch(createUniversity(values)).then(() => { reset(defaultValues); dispatch(alertSuccess(t('university.create_success_message'))); onClose(); }); } }); } catch (err) { dispatch(alertError(t('common.something_wrong_happend'))); console.error(err); } };
const update = async () => { try { trigger().then(async (isValid) => { if (isValid && currentUniversity?.id) { updateUniversity(currentUniversity.id, values).then(() => { dispatch(alertSuccess(t('university.update_success_message'))); reset(defaultValues); onClose(); }); } }); } catch (err) { dispatch(alertError(t('common.something_wrong_happend'))); } };
return (
); }`
### This is my new code with the solution
`//import all the statement
type University = { name: string; email: string; address: string; phoneNumber: string; };
const { createUniversity } = universityApi.endpoints;
export default function UniversityForm({ currentUniversity, isUpdate, onClose }: UniversityFormProps) {
const { t } = useTranslation();
const dispatch = useDispatch<ThunkDispatch<RootState, undefined, UniversityActionTypes>>();
const defaultValues = useMemo
// console.log("defaultValues", defaultValues)
const formData = { name: '', email: '', address: '', phoneNumber: '', };
const methods = useForm
const { updateUniversity, isLoading, error, data } = useUpdateUniversityMutation(); const { alertSuccess, alertError } = useSnackBar();
const { reset, handleSubmit, trigger, watch, formState: { isSubmitting }, } = methods;
const values = watch();
useEffect(() => { if (isUpdate && currentUniversity) { reset(defaultValues); } if (!isUpdate) { reset(defaultValues); } }, [isUpdate, currentUniversity]);
const onSubmit = async () => { if (!isUpdate) { create(); } else { update(); } };
const create = async () => { try { trigger().then(async (isValid) => { if (isValid) { dispatch(createUniversity(values)).then(() => { reset(defaultValues); dispatch(alertSuccess(t('university.create_success_message'))); onClose(); }); } }); } catch (err) { dispatch(alertError(t('common.something_wrong_happend'))); console.error(err); } };
const update = async () => { try { trigger().then(async (isValid) => { if (isValid && currentUniversity?.id) { updateUniversity(currentUniversity.id, values).then(() => { dispatch(alertSuccess(t('university.update_success_message'))); reset(defaultValues); onClose(); }); } }); } catch (err) { dispatch(alertError(t('common.something_wrong_happend'))); } };
return (
); } ` Compare both the solution you can find what we have changed and solved this Problem
Same issue
This is what my schema looks like
export const yup_TYPESCRIPTINTERFACE: SchemaOf<TYPESCRIPTINTERFACE> = yup.object().shape({
...
})
This is how I am using the schema with yupResolver
const methods = useForm<TYPESCRIPTINTERFACE>({
resolver: yupResolver(yup_TYPESCRIPTINTERFACE),
});
This is the error I get
Type error: Type 'Resolver<AssertsShape<{ NAME: BaseSchema<Maybe<Nullable<string>>, AnyObject, Nullable<string>>; IDENTIFIER: BaseSchema<Maybe<Nullable<string>>, AnyObject, Nullable<...>>; ... 10 more ...; createdAt: BaseSchema<...>; }>, any>' is not assignable to type 'Resolver<TYPESCRIPTINTERFACE, any>'.
Types of parameters 'values' and 'values' are incompatible.
Type 'TYPESCRIPTINTERFACE' is not assignable to type 'AssertsShape<{ NAME: BaseSchema<Maybe<Nullable<string>>, AnyObject, Nullable<string>>; IDENTIFIER: BaseSchema<Maybe<Nullable<string>>, AnyObject, Nullable<...>>; ... 10 more ...; createdAt: BaseSchema<...>; }>'.
I got the same issue
the dependencies
"@hookform/resolvers": "3.3.2",
"react-hook-form": "7.49.2",
"yup": "1.3.3"
this is my yup object
const schema = {
pin: yup.string().label('challengerService_PIN').required(),
};
export const pinFormSchema = yup.object(schema).required();
export type PinFormData = yup.InferType<typeof pinFormSchema>;
this is my useForm
const { control, reset, watch, handleSubmit } = useForm<PinFormData>({
mode: 'onChange',
defaultValues: defaultInitialValues,
resolver: yupResolver(pinFormSchema),
});
The error:
Expected 6 arguments, but got 1.ts(2554)
yup.d.ts(3, 138): An argument for '' was not provided.
(alias) yupResolver<FieldValues>(schema: any, : any, Yup: any, ObjectSchema: any, : any, TFieldValues: any): any
import yupResolver
any update on this issue
I've fixed it by downgrading @hookform/resolvers
version to 3.1.1
.
{
"@hookform/resolvers": "3.1.1",
"react-hook-form": "7.49.3",
"yup": "^1.3.3",
"typescript": "^5.3.3"
}
+1
Another possible fix for VS Code users is selecting workspace's TypeScript version(Cmd + Shift + P > TypeScript: Select TypeScript Version...).
I dont know why but just add //@ts-ignore to fix this:
const methods = useForm
Can you please provide a minimal reproducible example (e.g. a Codesandbox)?
Describe the bug i got this bug in my next app