Handling Overlapping Structs with `Schema.extend` in TypeScript

Why can't Schema.extend handle overlapping structs? Seems like we should be able to do something like:
const startsWith = Schema.String.pipe(Schema.startsWith('start:'));
const endsWith = Schema.String.pipe(Schema.endsWith(':end'));

const startStruct = Schema.Struct({
  key: startsWith,
});

const endStruct = Schema.Struct({
  key: endsWith,
});

/**
 * Error: Unsupported schema or overlapping types
 *   at path: ["key"]
 *   details: cannot extend string with a string ending with ":end"
 */
const schema = startStruct.pipe(Schema.extend(endStruct));

const decode = Schema.decodeSync(schema);
const actual = decode({ key: 'start:5:end' });
Was this page helpful?