Issue with `omit` method on extended structs in Effect Typescript library and possible workaround
Does it work as expected? Why one struct extended by another struct doesn't produce struct with omit method as a result? How can this be circumvented?
https://effect.website/play/#1a97d122506f
https://effect.website/play/#1a97d122506f
import { Schema } from "effect"
const OptionalProperty = Schema.optionalWith({ exact: true }) as <
S extends Schema.Schema.All
>(
self: S
) => Schema.optionalWith<S, { exact: true }>
const withRequiredName = Schema.extend(
Schema.Struct({
name: Schema.String
})
)
const withOptionalDescription = Schema.extend(
Schema.Struct({
description: Schema.String.pipe(OptionalProperty)
})
)
const UserGroup = Schema.Struct({
id: Schema.Number
}).pipe(withRequiredName, withOptionalDescription)
const notStructAnymore = Schema.asSchema(UserGroup)
// ^ Schema.Schema<{
// readonly id: number;
// readonly name: string;
// readonly description?: string;
// }, {
// readonly id: number;
// readonly name: string;
// readonly description?: string;
// }, never>
const UserGroupToInsert = UserGroup.omit("id")
// ERROR here because omit doesn't exist on the result type of extend
const UserGroupToInsert2 = Schema.Struct({
id: Schema.Number
}).omit("id")
// Works fineimport { Schema } from "effect"
const OptionalProperty = Schema.optionalWith({ exact: true }) as <
S extends Schema.Schema.All
>(
self: S
) => Schema.optionalWith<S, { exact: true }>
const withRequiredName = Schema.extend(
Schema.Struct({
name: Schema.String
})
)
const withOptionalDescription = Schema.extend(
Schema.Struct({
description: Schema.String.pipe(OptionalProperty)
})
)
const UserGroup = Schema.Struct({
id: Schema.Number
}).pipe(withRequiredName, withOptionalDescription)
const notStructAnymore = Schema.asSchema(UserGroup)
// ^ Schema.Schema<{
// readonly id: number;
// readonly name: string;
// readonly description?: string;
// }, {
// readonly id: number;
// readonly name: string;
// readonly description?: string;
// }, never>
const UserGroupToInsert = UserGroup.omit("id")
// ERROR here because omit doesn't exist on the result type of extend
const UserGroupToInsert2 = Schema.Struct({
id: Schema.Number
}).omit("id")
// Works fine