{"id":2109,"date":"2022-07-31T12:16:09","date_gmt":"2022-07-31T03:16:09","guid":{"rendered":"http:\/\/www.agile-software.site\/?p=2109"},"modified":"2023-07-29T15:53:27","modified_gmt":"2023-07-29T06:53:27","slug":"%e3%83%95%e3%82%a9%e3%83%bc%e3%83%a0%e3%81%ae%e3%83%90%e3%83%aa%e3%83%87%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3-yup","status":"publish","type":"post","link":"https:\/\/agile-software.net\/?p=2109","title":{"rendered":"\u30d5\u30a9\u30fc\u30e0\u306e\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3 Yup\u3068zod"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Yup<\/h2>\n\n\n\n<p>Yup\u306f\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306e\u305f\u3081\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002<br>\u5404\u30d5\u30a9\u30fc\u30e0\u9805\u76ee\u3054\u3068\u306b\u7570\u306a\u308b\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u5b9a\u7fa9\u3057\u3066\u3044\u304d\u307e\u3059\u3002<br>\u5ba3\u8a00\u7684\u3067\u5927\u5909\u308f\u304b\u308a\u3084\u3059\u3044\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u4efb\u610f\u306e\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u6271\u3046<\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>import * as yup from &#39;yup&#39;;\n\nconst schema = yup.object().shape({\n  name: yup.string().required(&#39;\u540d\u524d\u306f\u5fc5\u9808\u9805\u76ee\u3067\u3059&#39;),\n  age: yup.number(&#39;\u5e74\u9f62\u306f\u6570\u5024\u3067\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044&#39;) \/\/ \uff081\uff09\n    .required(&#39;\u5e74\u9f62\u306f\u5fc5\u9808\u9805\u76ee\u3067\u3059&#39;)\n    .positive(&#39;\u6b63\u306e\u6570\u3092\u6307\u5b9a\u3057\u3066\u304f\u3060\u3055\u3044&#39;)\n    .integer(&#39;\u6574\u6570\u3067\u6307\u5b9a\u3057\u3066\u304f\u3060\u3055\u3044&#39;),\n  email: yup.string().email(&#39;\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u306e\u5f62\u5f0f\u304c\u4e0d\u6b63\u3067\u3059&#39;),\n});\n\nschema\n  .validate({\n    name: &#39;Taro&#39;,\n    age: &#39;hi&#39;, \/\/ \u6570\u5024\u578b\u3067\u306f\u306a\u304f\u6587\u5b57\u5217\u578b\u3092\u6e21\u3057\u3066\u3044\u308b\n  })\n  .catch(function (err) {\n    console.log(err.errors); \/\/ =&gt; [&#39;\u5e74\u9f62\u306f\u6570\u5024\u3067\u5165\u529b\u3057\u3066\u304f\u3060\u3055\u3044&#39;] \/\/ \uff082\uff09\n  });<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">@hookform\/resolvers<\/h3>\n\n\n\n<p><strong>yupResolver<\/strong>\u3092import\u3057\u3066\u3001yup\u3067\u4f5c\u6210\u3057\u305f\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3068react-hook-form\u3092\u63a5\u7d9a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">zod<\/h2>\n\n\n\n<p>\u30b9\u30ad\u30fc\u30de\u3092\u5b9a\u7fa9\u3057\u3001\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306e\u8a2d\u5b9a\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br>\u307e\u305f\u5b9a\u7fa9\u3057\u305f\u30b9\u30ad\u30fc\u30de\u304b\u3089TypeScript\u306e\u578b\u3092\u751f\u6210\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yup Yup\u306f\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u306e\u305f\u3081\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002\u5404\u30d5\u30a9\u30fc\u30e0\u9805\u76ee\u3054\u3068\u306b\u7570\u306a\u308b\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u3092\u5b9a\u7fa9\u3057\u3066\u3044\u304d\u307e\u3059\u3002\u5ba3\u8a00\u7684\u3067\u5927\u5909\u308f\u304b\u308a\u3084\u3059\u3044\u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u304c\u53ef\u80fd\u3067\u3059\u3002 \u4efb\u610f\u306e\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u6271\u3046 @hookform\/re<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jin_ogp_image_url":"","_jin_last_featured_id":0,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2109","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts\/2109","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2109"}],"version-history":[{"count":3,"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts\/2109\/revisions"}],"predecessor-version":[{"id":2679,"href":"https:\/\/agile-software.net\/index.php?rest_route=\/wp\/v2\/posts\/2109\/revisions\/2679"}],"wp:attachment":[{"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/agile-software.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}