Effect CommunityEC
Effect Communityβ€’2y agoβ€’
41 replies
Kristian Notari

Improving Schema Composition: Allowing Precise Outputs with Generic Inputs Without Strict Mode

With regards to Schema.compose, is it true that when composing a precise output with a more generic input, would be ok to make it so they can be composed without specifying the strict: false option?

For example:
type NonEmptyString = string & Brand<something>
// trying to convert from a string to a number, handling empty string as null instead of "not a number"
declare const a: Schema<NonEmptyString | null, string>
declare const b: Schema<number | null, string | null>
const composed = Schema.compose(a,b) // error, but should be allowed?
const composed = Schema.compose(a,b, { strict: false }) // ok, but I lose type safety from now on if types change
Was this page helpful?