Open joshuaavalon opened 1 month ago
import { Type } from "@sinclair/typebox"; import type { StaticDecode, StaticEncode, TSchema } from "@sinclair/typebox"; const schema = Type.Recursive(self => Type.Object({ a: Type.Number(), b: Type.Transform(Type.Union([self, Type.Null(), Type.Undefined()])) .Decode(v => v ?? undefined) .Encode(v => v) })); /** type A = { a: number; b: ... | null | undefined; } */ type A = StaticEncode<typeof schema>; /** type B = { a: number; b: undefined; } */ type B = StaticDecode<typeof schema>;
You can see b is resolved to undefined even though it should be B | undefined.
b
undefined
B | undefined
You can see
b
is resolved toundefined
even though it should beB | undefined
.