S.never cannot be used in S.struct fields
NexZhu opened this issue Β· comments
π Bug report
Current Behavior
In Zod, one can use z.never()
to type z.object
fields:
export const villainSchema = z.object({
name: z.string(),
canBeTrusted: z.never(),
})
In @effect/schema
, this is not supported currently:
export const villainSchema: S.Schema<Villain> = S.struct({
name: S.string,
canBeTrusted: S.never,
})
Type error:
Type 'Schema<never, never>' is not assignable to type 'OptionalSchema<any, any> | Schema<any, any>'.
Type 'Schema<never, never>' is not assignable to type 'Schema<any, any>'.
Types of property 'From' are incompatible.
Type '(_: never) => never' is not assignable to type '(_: any) => any'.
Types of parameters '_' and '_' are incompatible.
Type 'any' is not assignable to type 'never'.ts(2322)
(property) canBeTrusted: S.Schema<never, never>
Expected behavior
Allow S.never
in S.struct
fields
Which versions of @effect/schema
are affected by this issue? Did this work in previous versions of @effect/schema
?
Software | Version(s) |
---|---|
@effect/schema | v0.12.1 |
TypeScript | 5.0.0 |
@NexZhu what's the use case? parsing is going to always fail
To forbid some fields to exist in the object. Similar to TypeSript:
type Obj = {
forbidden: never
}