Effect CommunityEC
Effect Community3y ago
7 replies
RJ

Questioning the classification of behavior as a bug

Am I right to call this behavior a bug?

import * as Schema from "@effect/schema/Schema";

const MySchema = Schema.union(
  Schema.struct({
    type: Schema.struct({
      name: Schema.literal("First"),
      thingOne: Schema.number,
    }),
  }),
  Schema.struct({
    type: Schema.struct({
      name: Schema.literal("Second"),
      thingTwo: Schema.string,
    }),
  }),
);

Schema.parseSync(MySchema)({ type: { name: "First", thingThree: 2 } })
/*
Uncaught Error: error(s) found
├─ union member
│  └─ ["type"]["thingOne"]
│     └─ is missing
└─ union member
   └─ ["type"]["name"]
      └─ Expected "Second", actual "First"
*/

Schema.parseSync(MySchema)({ type: { name: "Second", thingThree: 2 } })
/*
Uncaught Error: error(s) found
├─ union member
│  └─ ["type"]["name"]
│     └─ Expected "First", actual "Second"
└─ union member
   └─ ["type"]["thingTwo"]
      └─ is missing
*/


In each case I expected the parse error for ["type"]["thingTwo"] or ["type"]["thingOne"], but not for ["type"]["name"].

(I agree that "type" is a pointless wrapper here; this example is based on data I don't control)
Was this page helpful?