Effect CommunityEC
Effect Community16mo ago
8 replies
Josh

Selective Property Decoding in Structs Without Losing Input Types

is there a way to decode a struct but only decode a few properties and not lose the type of the other input properties? For example I have an object coming from prisma that might have 20 or more properties and there's some application level constraints on some of the values that aren't represented in the DB schema. I was hoping to use Schema to help guard the writes and reads to ensure only valid values are being used. However, I'm not sure that's possible as all the decoding stuff seems to be built on the premise of the input type is unknown. I don't see a way to not lose the input type even when using onExcessProperty: 'preserve'. Could always get it done with casting or decoding the "special" fields and manually creating the desired shape by spreading in the input and overriding those properties with the decode output.
Was this page helpful?