Skip to content

v0.62.0

Choose a tag to compare

@github-actions github-actions released this 09 Dec 18:59
· 210 commits to main since this release
4b1cecb

Minor Changes

  • #528 7dc14cf Thanks @mattiamanzati! - Add typeToSchema codegen

    This adds a new // @effect-codegens typeToSchema codegen that automatically generates Effect Schema classes from TypeScript types. Given a type alias with object members representing schemas to generate (e.g., type ToGenerate = { UserSchema: User, TodoSchema: Todo }), the codegen will create the corresponding Schema class definitions.

    The generated schemas:

    • Automatically detect and reuse existing schema definitions in the file
    • Support both type aliases and interfaces
    • Include outdated detection to warn when the source type changes
    • Work with the outdatedEffectCodegen diagnostic to provide automatic fix actions

    Example usage:

    type User = {
      id: number;
      name: string;
    };
    
    // @effect-codegens typeToSchema
    export type ToGenerate = {
      UserSchema: User;
    };
    
    // Generated by the codegen:
    export class UserSchema extends Schema.Class<UserSchema>("UserSchema")({
      id: Schema.Number,
      name: Schema.String,
    }) {}

Patch Changes

  • #530 5ecdc62 Thanks @mattiamanzati! - Fix Refactor to Schema (Recursive Structural) to support exactOptionalPropertyTypes

    When exactOptionalPropertyTypes is enabled in tsconfig, optional properties with types like string | undefined are not assignable to types defined as prop?: string. This fix generates Schema.optionalWith(Schema.String, { exact: true }) instead of Schema.optional(Schema.Union(Schema.Undefined, Schema.String)) to maintain type compatibility with external libraries that don't always include undefined in their optional property types.

    Example:

    // With exactOptionalPropertyTypes enabled
    type User = {
      name?: string; // External library type (e.g., Stripe API)
    };
    
    // Generated schema now uses:
    Schema.optionalWith(Schema.String, { exact: true });
    
    // Instead of:
    Schema.optional(Schema.Union(Schema.Undefined, Schema.String));

    This ensures the generated schema maintains proper type compatibility with external libraries when using strict TypeScript configurations.