Issue with Merging Transformed Structs in Effect Typescript
I thought I could merge a Struct generated with
I am trying to map
I defined a
Then I tried to merge it with another Struct containing the rest of my fields:
However, I get a runtime error:
An alternate, simpler, design is the following, but there are several things I don't like about it:
-
-
What do you think?
Schema.transform with another using Schema.extend, but I can't get it to work.I am trying to map
{fallback: 0|1, ...rest} to {fallback?: true, ...rest}. I defined a
fallback Struct which can either be {} or {fallback: true} (this part behaves as expected)Then I tried to merge it with another Struct containing the rest of my fields:
However, I get a runtime error:
Unsupported schema or overlapping types
cannot extend{ readonly id: number; readonly type: "lesson" | "playground"; readonly ordering: number; readonly published: BooleanFromUnknown; readonly title: string; readonly slug: string }withwith ({ readonly fallback: 0 | 1 } <-> { readonly fallback: true } | {})
An alternate, simpler, design is the following, but there are several things I don't like about it:
-
Encoded will give me {fallback?: 1 | 0 | undefined, ...rest} which is not correct-
S.decodeUnknown will output {fallback: undefined, ...rest} instead of omitting fallback when it is 0, which can't be converted to JSON.What do you think?
