Challenges with Defining Type Guard for Allowed Schemas
Hi all! I'm trying to build an abstraction on top of
@effect/schema
@effect/schema
and I'm running into the issue that I want to define a type guard to constrain allowed schemas:
type AllowedShape = { [key: string]: Schema<any, string, never>}
type AllowedShape = { [key: string]: Schema<any, string, never>}
To mean: "valid field schemas are any schema that can encode to string" (and don't need any context)
But because of how the variance for
I
I
and
A
A
is set up (invariant), actual schemas that conform to the intended contract are incompatible on assignment.
The variance setup makes sense to prevent incompatible schemas being used interchangably, but it makes it hard (impossible?) to "talk about" types of schemas before they are used.