Zod
https://gyazo.com/46cf504b2ae0287f3023c2cf64bc0e9a
v3まででてる
開発者は@colinhacks
github
zod.refine()
zod.transform()
zod.brand()
zod.discriminatedUnion()
zod.custom<T>()
ZodError
#WIP
#??
必須ってどうやって定義するの
defaultで必須で、任意の時にoptional()をつけるのか
zod.arrayやzod.stringではzod.nonempty()が使える
後者、何故かdocsに書いてない
ts型定義をzodに変換する
ts-to-zod
https://github.com/fabien0102/ts-to-zod
https://github.com/bradennapier/zod-vscode-extension
vscode
以下のどれで定義するのかを指標が欲しいな
普通にtype
value as const
zod
infer typeするのが面倒jjk
ZodでDateを扱う
zod.unwrap()
.optional()とか.nullable()だったものを、通常のTに戻す
code:ts
const stringSchema = z.string();
const nullableString = stringSchema.nullable();
nullableString.unwrap() === stringSchema; // true
docsよみ(読んだら消す)
Coercion for primitives
Literals
NaNs
Booleans
Dates
zod.object()
.keyof
.merge
.pick/.omit
.partial
.deepPartial
.passthrough
.strict
.strip
.catchall
Arrays
.element
.nonempty
.min/.max/.length
Tuples
Records
Maps
Sets
Intersections
Recursive types
JSON type
Cyclical data
Promises
Instanceof
Functions
Preprocess
Schema methods
zod.parse()
zod.parseAsync()
zod.safeParse()
zod.safeParseAsync()
.superRefine
.array
.promise
.and
Guides and concepts
Type inference
Writing generic functions