Effect CommunityEC
Effect Community•3y ago•
17 replies
bug

Partial schema type

Hi! I want to define a type that specifies a subset/partial of some schema. How can I redefine PartialSchema<T> such that the following code typechecks correctly?

type PartialSchema<T> = Schema.Schema<Partial<T>>

//    v Type 'Partial<{ foo: string; bar: { bin: string; }; }>' is not assignable to type '{ readonly foo: string; }'.
const ps: PartialSchema<{ foo: string; bar: { bin: string } }> = Schema.struct({
  foo: Schema.string,
})


tsc is expecting is the following (which i can make sense of... i just can't work backwards to what im expecting):

type PartialSchema<T> = Schema.Schema<Partial<T>>

const ps: PartialSchema<{ foo: string; bar: { bin: string } }> = Schema.struct({
  foo: Schema.optional(Schema.string),
})


i feel like i am missing something obvious 🤷
Was this page helpful?