貼文討論:[問題] Zod 的 .optional() 使用方法



hi

zod 通常是拿來做表單或 api 資料的型別驗證, 我看到的大多作法是自己定義 type, 加上使用 react 的 ComponentProps, 這樣還可以獲得 html 的原始 props。

import { ComponentProps } from "react";
type MyDivProps = ComponentProps<"div"> & {
  myProp: string;
};
const MyDiv = ({ myProp, ...props }: MyDivProps) => {
  console.log(myProp!);
  return <div {...props} />;
};

參考 : https://www.totaltypescript.com/react-component-props-type-helper


此人尚未填寫簡介。