Effect CommunityEC
Effect Community2y ago
89 replies
Anna | DevMiner

Writing Schemas to Wrap Other Schemas: Dealing with the New Context Generic

The new Context generic for Schemas is really messing up my code...

How should we write schemas that wrap other schemas?
For example this is my OkResult type from typed-at-rest using effect/schema from 4 months ago or so
export const OkResultSchema = <T>(inner: S.Schema<any, T>) => S.struct({ ok: S.literal(true), data: inner });
export type OkResult<T> = S.Schema.To<ReturnType<typeof OkResultSchema<T>>>;
export const makeOkResult = <T>(inner: T) => ({ ok: true, data: inner }) as const;
export type inferOkResult<R> = R extends OkResult<infer Res> ? Res : never;
Was this page helpful?