Repository navigation
v0.62.0
Minor Changes
-
#528
7dc14cfThanks @mattiamanzati! - Add typeToSchema codegenThis adds a new
// @effect-codegens typeToSchemacodegen 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
outdatedEffectCodegendiagnostic 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
5ecdc62Thanks @mattiamanzati! - FixRefactor to Schema (Recursive Structural)to supportexactOptionalPropertyTypesWhen
exactOptionalPropertyTypesis enabled in tsconfig, optional properties with types likestring | undefinedare not assignable to types defined asprop?: string. This fix generatesSchema.optionalWith(Schema.String, { exact: true })instead ofSchema.optional(Schema.Union(Schema.Undefined, Schema.String))to maintain type compatibility with external libraries that don't always includeundefinedin 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.