Effect CommunityEC
Effect Community2y ago
4 replies
Nanniiii

Validating GraphQL Enum Types with Schema in TypeScript

Hi, i'm trying schema to see if it can do what i can't in zod.

i have a gql types generated with gql.tada which give me a type for an enum type F = "ONE" | "TWO" | "THREE";

so i want to create a
schema
validation that is checked again that type, so typescript would tell me if it's not matching anymore.

so i create const Frequency = Schema.Literal("ONE", "TWO", "THREE") but then not sure how to check that it matched the type i get from gql. was trying to look into declare but can't figure it out :/

so if later the back team add to F FOUR i'd like my typescript check to throw an error saying Frequency is missing FOUR

the plan is to use the schema to validate with react-hook-form
Was this page helpful?