Effect CommunityEC
Effect Community12mo ago
10 replies
Dave Meehan

Schema.Struct that is optional with defaults, and has option with default members

const schema = Schema.Struct({
  Foo: Schema.String.pipe(Schema.optionalWith({ default: () => 'bar' }))
}).pipe(Schema.optionalWith({ default: () => ({}) }))

Gives: "Type '() => undefined' is not assignable to type 'LazyArg<{ readonly Foo: string; }>'" for the () => undefined

And on usage,

yield* Schema.decodeUnknown(schema)(undefined)


Gives: "Argument of type 'optionalWith<Struct<{ Foo: optionalWith<typeof String$, { default: () => string; }>; }>, OptionalOptions<{ readonly Foo: string; }>>' is not assignable to parameter of type 'Schema<unknown, unknown, unknown>'" for the
schema


I want the struct to be optional, and be filled with member defaults if undefined. If it is supplied, any missing members should be get defaults.

TIA
Was this page helpful?