Is it possible to use Transform for Recursive type? #590
Replies: 2 comments 1 reply
-
@joshuaavalon Hi, The Decode function will infer as the return type, however in your implementation, you have only applied the ?? operator to the top level const transform = Type.Transform(schema)
.Decode(v => {
const { not, ...others } = v;
return { ...others, not: not ?? undefined }; // <- nullish only applied for top-level not
})
.Encode(v => v);
type T = StaticDecode<typeof transform> // type T = {
// not: { // <- correctly mapped
// not?: ... | null | undefined; // <- not recursively mapped
// equals?: Date | undefined;
// in?: Date[] | undefined;
// notIn?: Date[] | undefined;
// lt?: Date | undefined;
// lte?: Date | undefined;
// gt?: Date | undefined;
// gte?: Date | undefined;
// } | undefined;
// ... 6 more ...;
// gte?: Date | undefined;
// } To map for this type, I would recommend extracting the decode logic from the callback, and implement as separate function which returns the Hope this helps |
Beta Was this translation helpful? Give feedback.
-
Yes, I understand I it only decode the top level. However, I believe For example, |
Beta Was this translation helpful? Give feedback.
-
As title. Is it possible to use
Type.Recursive
withType.Transform
?For example, I want to replace
null
withundefined
duringDecode
.However,
not
is not decoded recursivelyBeta Was this translation helpful? Give feedback.
All reactions