Effect CommunityEC
Effect Community2y ago
7 replies
attila

Schema_EXTENSION issues with extending a string schema with an empty struct in TypeScript

Is there a reason why the following is not allowed?
const stringObject = Schema.String.pipe(
  Schema.extend(Schema.Struct({}))
)
// Error: extend: unsupported schema or overlapping types, cannot extend string with {}

In TS, it's perfectly fine to have string & {}. It's commonly used in situations that need to describe a few known values and the "rest". E.g.:
type EventType = "EventA" | "EventB" | string & {}

This will result in having an experience in which one gets correct code suggestions listing EventA and EventB as an option but the value can indeed be anything else, too.
Was this page helpful?