Transforming Optional Properties in Schema with TypeScript

Is it possible to Schema.transform an optional property? I was hoping to do something like this (inside an outer struct):
...other fields,
requestType: Schema.transform(
  pipe(
    Schema.optionalWith(
      Schema.Struct({
        requestType: Schema.Struct({
          id: Schema.String,
        }),
      }),
      {as: 'Option'}
    ),
    Schema.fromKey('foobar'),
  ),
  Schema.String,
  {
    strict: true,
    encode: (value) => ({ requestType: { id: value } }),
    decode: (value) => pipe(value, Option.map(x => x.requestType.id), Option.getOrElse(() => 'fallback')),
  },
),
Was this page helpful?