{"id":480738,"date":"2026-05-23T09:50:13","date_gmt":"2026-05-23T09:50:13","guid":{"rendered":"https:\/\/savepearlharbor.com\/?p=480738"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=480738","title":{"rendered":"\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u0438 \u0444\u043e\u0440\u043c\u044b React Hook Form (\u2265 v7.44.0) + Zod \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0432\u0445\u043e\u0434\u043d\u044b\u043c\u0438 \u0438 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438"},"content":{"rendered":"<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0420\u0430\u0431\u043e\u0442\u0430\u044f \u0441 \u0444\u043e\u0440\u043c\u043e\u0439, \u0447\u0430\u0441\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043d\u0430 \u0432\u0445\u043e\u0434 \u043e\u043d\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u043b\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430, \u0430 \u043f\u043e\u0441\u043b\u0435 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0438\u0445 \u0442\u0438\u043f \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f<\/p>\n<p>\u041c\u043e\u044f \u0444\u043e\u0440\u043c\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043f\u043e\u043b\u0435\u0439, \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 &#8212; \u043f\u0443\u0441\u0442\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430, \u0430 \u043f\u043e\u0441\u043b\u0435 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 &#8212; \u0447\u0438\u0441\u043b\u043e<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0445\u0435\u043c\u0443 \u0434\u043b\u044f \u0442\u0430\u043a\u043e\u0439 \u0444\u043e\u0440\u043c\u044b \u0438 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0438\u0437 \u043d\u0435\u0435 \u0442\u0438\u043f<\/p>\n<pre><code class=\"typescript\">const EMPTY_NUMERIC = '';const numericScheme = z.union([z.number(), z.literal('')]);type NumericValue = z.infer&lt;typeof numericScheme&gt;;const requiredNumberWithRefine = numericScheme.refine(  (val) =&gt; val !== EMPTY_NUMERIC,  {    message: '\u042d\u0442\u043e \u043f\u043e\u043b\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f',  },);export const formSchema = z.object({  amount: requiredNumberWithRefine,  quantity: requiredNumberWithRefine,});export type FormDataInfer = z.infer&lt;typeof formSchema&gt;;<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:87px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441 infer \u043d\u0435 \u043f\u043e\u0434\u043e\u0439\u0434\u0435\u0442 \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u043e\u0440\u043c\u0443 \u0438 \u0437\u0430\u0434\u0430\u0442\u044c \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0445\u0443\u043a\u0435 useForm \u043f\u043e\u0441\u044b\u043f\u044f\u0442\u0441\u044f \u043e\u0448\u0438\u0431\u043a\u0438 \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u0438<\/p>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/91f\/875\/d62\/91f875d62b4064e3e1fc915a96b876bf.png\" width=\"1224\" height=\"544\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/91f\/875\/d62\/91f875d62b4064e3e1fc915a96b876bf.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/91f\/875\/d62\/91f875d62b4064e3e1fc915a96b876bf.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 v7.44.0 (<a href=\"https:\/\/github.com\/react-hook-form\/react-hook-form\/releases\/tag\/v7.44.0\" rel=\"noopener noreferrer nofollow\">\u0440\u0435\u043b\u0438\u0437<\/a>) React Hook Form \u0445\u0443\u043a useForm \u0441\u0442\u0430\u043b \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a<\/p>\n<pre><code class=\"typescript\"> useForm&lt;TFieldValues extends FieldValues = FieldValues, TContext = any, TTransformedValues = TFieldValues&gt;<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041f\u043e\u044f\u0432\u0438\u043b\u0441\u044f 3-\u0438\u0439 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a TTransformedValues &#8212; \u043e\u043d \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0444\u043e\u0440\u043c\u044b, \u043f\u043e\u0441\u043b\u0435 \u0438\u0445 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438<\/p>\n<p>\u0412 \u043d\u0430\u0448\u0435\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0443\u0437\u0438\u0442\u044c \u043d\u0430\u0448 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u0442\u0438\u043f NumericValue \u0434\u043e number \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 &#8212; refine, transform, superRefine \u0441 pipe. \u041c\u044b \u0443\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c refine \u0432 \u0441\u0445\u0435\u043c\u0435 requiredNumberWithRefine, \u043e\u043d \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442, \u043d\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u044b c transform \u0438 superRefine+pipe*, \u0435\u0441\u043b\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b \u0437\u0430\u0445\u043e\u0442\u0438\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442<\/p>\n<p>* \u0435\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e superRefine, \u0442\u0438\u043f \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u0443\u0436\u0435\u043d<\/p>\n<pre><code class=\"typescript\">const requiredNumberWithTransform = numericScheme.transform(  (val: NumericValue, ctx: z.RefinementCtx) =&gt; {    if (val === EMPTY_NUMERIC) {      ctx.addIssue({        code: 'custom',        message: '\u042d\u0442\u043e \u043f\u043e\u043b\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f',      });      return z.NEVER;    }    return val;  },);const requiredNumberWithSuperRefineAndPipe = numericScheme  .superRefine((val, ctx) =&gt; {    if (val === EMPTY_NUMERIC) {      ctx.addIssue({        code: 'custom',        message: '\u042d\u0442\u043e \u043f\u043e\u043b\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f',      });    }  })  .pipe(z.number());<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u043c 2 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0442\u0438\u043f\u0430 FormDataInput \u0438 FormDataOutput \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u0432\u00a0 z.input \u0438 z.output\u00a0<\/p>\n<pre><code class=\"typescript\">export type FormDataInput = z.input&lt;typeof formSchema&gt;;export type FormDataOutput = z.output&lt;typeof formSchema&gt;;<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a\u0438\u0435 \u0442\u0438\u043f\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438\u0441\u044c, \u0442\u043e \u0443\u0432\u0438\u0434\u0438\u043c<\/p>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/06b\/589\/f12\/06b589f122d47917a4840a5181354087.png\" width=\"894\" height=\"328\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/06b\/589\/f12\/06b589f122d47917a4840a5181354087.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/06b\/589\/f12\/06b589f122d47917a4840a5181354087.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<figure class=\"full-width \"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/80d\/330\/9ef\/80d3309ef85d38f1bbefcdc87dfc6a83.png\" width=\"940\" height=\"322\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/80d\/330\/9ef\/80d3309ef85d38f1bbefcdc87dfc6a83.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/80d\/330\/9ef\/80d3309ef85d38f1bbefcdc87dfc6a83.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u0443\u0435\u043c defaultValues \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e FormDataInput, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u044d\u0442\u0438 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0438 \u0432 \u0445\u0443\u043a\u0435 useForm (\u0435\u0441\u043b\u0438 \u043c\u044b \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0442\u0438\u043f\u044b \u0432 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0438 \u044f\u0432\u043d\u043e, \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0432\u0435\u0434\u0435\u043d\u044b \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e, \u043d\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u044d\u0442\u043e \u0434\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438), \u0432 \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u0435 onSubmit \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c FormDataOutput<\/p>\n<p>\u0412\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"typescript\">const defaultValues: FormDataInput = {  amount: '',  quantity: '',};const Form = () =&gt; {  const {    handleSubmit,    control,    formState: { errors },  } = useForm&lt;FormDataInput, unknown, FormDataOutput&gt;({    resolver: zodResolver(formSchema),    defaultValues,  });  const onSubmit = (data: FormDataOutput) =&gt; {    saveData(data);  };  return (    &lt;form      onSubmit={handleSubmit(onSubmit)}      ...<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0412\u0441\u0435, \u0442\u0435\u043f\u0435\u0440\u044c \u044f\u0432\u043d\u043e \u0432\u0438\u0434\u043d\u043e \u043a\u0430\u043a\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0444\u043e\u0440\u043c\u0430 \u043d\u0430 \u0432\u0445\u043e\u0434\u0435 \u0438 \u0432\u044b\u0445\u043e\u0434\u0435, \u043f\u043b\u044e\u0441 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0442\u0434\u0435\u043b\u044f\u0442\u044c \u0447\u0430\u0441\u0442\u0438 \u0444\u043e\u0440\u043c\u044b \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b, \u0444\u0430\u0439\u043b\u044b \u0438 \u0431\u0435\u0437\u0431\u043e\u043b\u0435\u0437\u043d\u0435\u043d\u043d\u043e \u0438\u0445 \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u00a0<\/p>\n<\/div>\n<p>\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/1038440\/\">https:\/\/habr.com\/ru\/articles\/1038440\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0420\u0430\u0431\u043e\u0442\u0430\u044f \u0441 \u0444\u043e\u0440\u043c\u043e\u0439, \u0447\u0430\u0441\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043d\u0430 \u0432\u0445\u043e\u0434 \u043e\u043d\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u043b\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430, \u0430 \u043f\u043e\u0441\u043b\u0435 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0438\u0445 \u0442\u0438\u043f \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f\u041c\u043e\u044f \u0444\u043e\u0440\u043c\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043f\u043e\u043b\u0435\u0439, \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 &#8212; \u043f\u0443\u0441\u0442\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430, \u0430 \u043f\u043e\u0441\u043b\u0435 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 &#8212; \u0447\u0438\u0441\u043b\u043e\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0445\u0435\u043c\u0443 \u0434\u043b\u044f \u0442\u0430\u043a\u043e\u0439 \u0444\u043e\u0440\u043c\u044b \u0438 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0438\u0437 \u043d\u0435\u0435 \u0442\u0438\u043fconst EMPTY_NUMERIC = &#187;;const numericScheme = z.union([z.number(), z.literal(&#187;)]);type NumericValue = z.infer&lt;typeof numericScheme&gt;;const requiredNumberWithRefine = numericScheme.refine(  (val) =&gt; val !== EMPTY_NUMERIC,  {    message: &#8216;\u042d\u0442\u043e \u043f\u043e\u043b\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f&#8217;,  },);export const formSchema = z.object({  amount: requiredNumberWithRefine,  quantity: requiredNumberWithRefine,});export type FormDataInfer = z.infer&lt;typeof formSchema&gt;;\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441 infer \u043d\u0435 \u043f\u043e\u0434\u043e\u0439\u0434\u0435\u0442 \u0432 \u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u043e\u0440\u043c\u0443 \u0438 \u0437\u0430\u0434\u0430\u0442\u044c \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0445\u0443\u043a\u0435 useForm \u043f\u043e\u0441\u044b\u043f\u044f\u0442\u0441\u044f \u043e\u0448\u0438\u0431\u043a\u0438 \u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u0438\u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 v7.44.0 (\u0440\u0435\u043b\u0438\u0437) React Hook Form \u0445\u0443\u043a useForm \u0441\u0442\u0430\u043b \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a useForm&lt;TFieldValues extends FieldValues = FieldValues, TContext = any, TTransformedValues = TFieldValues&gt;\u041f\u043e\u044f\u0432\u0438\u043b\u0441\u044f 3-\u0438\u0439 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a TTransformedValues &#8212; \u043e\u043d \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0444\u043e\u0440\u043c\u044b, \u043f\u043e\u0441\u043b\u0435 \u0438\u0445 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438\u0412 \u043d\u0430\u0448\u0435\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0443\u0437\u0438\u0442\u044c \u043d\u0430\u0448 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u0442\u0438\u043f NumericValue \u0434\u043e number \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 &#8212; refine, transform, superRefine \u0441 pipe. \u041c\u044b \u0443\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c refine \u0432 \u0441\u0445\u0435\u043c\u0435 requiredNumberWithRefine, \u043e\u043d \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442, \u043d\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u044b c transform \u0438 superRefine+pipe*, \u0435\u0441\u043b\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b \u0437\u0430\u0445\u043e\u0442\u0438\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442* \u0435\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e superRefine, \u0442\u0438\u043f \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u0443\u0436\u0435\u043dconst requiredNumberWithTransform = numericScheme.transform(  (val: NumericValue, ctx: z.RefinementCtx) =&gt; {    if (val === EMPTY_NUMERIC) {      ctx.addIssue({        code: &#8216;custom&#8217;,        message: &#8216;\u042d\u0442\u043e \u043f\u043e\u043b\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f&#8217;,      });      return z.NEVER;    }    return val;  },);const requiredNumberWithSuperRefineAndPipe = numericScheme  .superRefine((val, ctx) =&gt; {    if (val === EMPTY_NUMERIC) {      ctx.addIssue({        code: &#8216;custom&#8217;,        message: &#8216;\u042d\u0442\u043e \u043f\u043e\u043b\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f&#8217;,      });    }  })  .pipe(z.number());\u0414\u0430\u043b\u0435\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u043c 2 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0442\u0438\u043f\u0430 FormDataInput \u0438 FormDataOutput \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u0432\u00a0 z.input \u0438 z.output\u00a0export type FormDataInput = z.input&lt;typeof formSchema&gt;;export type FormDataOutput = z.output&lt;typeof formSchema&gt;;\u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a\u0438\u0435 \u0442\u0438\u043f\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438\u0441\u044c, \u0442\u043e \u0443\u0432\u0438\u0434\u0438\u043c\u0422\u0435\u043f\u0435\u0440\u044c \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u0443\u0435\u043c defaultValues \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e FormDataInput, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u044d\u0442\u0438 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0438 \u0432 \u0445\u0443\u043a\u0435 useForm (\u0435\u0441\u043b\u0438 \u043c\u044b \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0442\u0438\u043f\u044b \u0432 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0438 \u044f\u0432\u043d\u043e, \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0432\u0435\u0434\u0435\u043d\u044b \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e, \u043d\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u044d\u0442\u043e \u0434\u043b\u044f \u043d\u0430\u0433\u043b\u044f\u0434\u043d\u043e\u0441\u0442\u0438), \u0432 \u0445\u0435\u043d\u0434\u043b\u0435\u0440\u0435 onSubmit \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c FormDataOutput\u0412\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a:const defaultValues: FormDataInput = {  amount: &#187;,  quantity: &#187;,};const Form = () =&gt; {  const {    handleSubmit,    control,    formState: { errors },  } = useForm&lt;FormDataInput, unknown, FormDataOutput&gt;({    resolver: zodResolver(formSchema),    defaultValues,  });  const onSubmit = (data: FormDataOutput) =&gt; {    saveData(data);  };  return (    &lt;form      onSubmit={handleSubmit(onSubmit)}      &#8230;\u0412\u0441\u0435, \u0442\u0435\u043f\u0435\u0440\u044c \u044f\u0432\u043d\u043e \u0432\u0438\u0434\u043d\u043e \u043a\u0430\u043a\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0444\u043e\u0440\u043c\u0430 \u043d\u0430 \u0432\u0445\u043e\u0434\u0435 \u0438 \u0432\u044b\u0445\u043e\u0434\u0435, \u043f\u043b\u044e\u0441 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0442\u0434\u0435\u043b\u044f\u0442\u044c \u0447\u0430\u0441\u0442\u0438 \u0444\u043e\u0440\u043c\u044b \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b, \u0444\u0430\u0439\u043b\u044b \u0438 \u0431\u0435\u0437\u0431\u043e\u043b\u0435\u0437\u043d\u0435\u043d\u043d\u043e \u0438\u0445 \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u00a0\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 https:\/\/habr.com\/ru\/articles\/1038440\/<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-480738","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/480738","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=480738"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/480738\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=480738"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=480738"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=480738"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}