Optional passing for null? #759
-
Hi, I use a generator to build typebox schemas from my prisma schema. Optional fields from Prisma are returned as value or null. But the typebox typescript type which is derived from the use with Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
@m1212e Hi,
Try the following import { Type, Static, TSchema } from '@sinclair/typebox'
const Nullable = <T extends TSchema>(schema: T) => Type.Union([Type.Null(), schema])
const T = Type.Object({
name: Nullable(Type.String()),
level: Nullable(Type.Number()),
enabled: Nullable(Type.Boolean())
})
type T = Static<typeof T> Just keep in mind that Optional means "the property key is optional" (so is somewhat unrelated to Hope this helps |
Beta Was this translation helpful? Give feedback.
@m1212e Hi,
Try the following
TypeScript Link Here
Just kee…