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.
Uh oh!
There was an error while loading. Please reload this page.
-
As title. Is it possible to use
Type.RecursivewithType.Transform?For example, I want to replace
nullwithundefinedduringDecode.However,
notis not decoded recursivelyBeta Was this translation helpful? Give feedback.
All reactions