Effect CommunityEC
Effect Community17mo ago
7 replies
Guido

Ensuring Schema Subset Validity in TypeScript with @effect/schema

asd is a field that doesn't exist in Foo. Is there a way of creating a derived Schema class so that it's enforced to contain a subset of the fields of another? (for example make sure that Bar can't have fields not present in Foo? (In typescript I'd extend or intersect another type. something like that)

import * as S from '@effect/schema/Schema';

import { Foo } from '../../shared/models/db_v0/Foo';

export class Bar extends S.Class<Bar>('Bar')({
  id: Foo.fields.id,
  type: Foo.fields.type,
  content: Foo.fields.content,
  title: Foo.fields.title,
  asd: S.Struct({
    asd: S.String,
  }),
}) {}
Was this page helpful?