Effect CommunityEC
Effect Community2y ago
24 replies
anselm

Challenges with Defining Type Guard for Allowed Schemas

Hi all! I'm trying to build an abstraction on top of @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>
}


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
and
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.

Any advice? Thanks a lot!
Was this page helpful?