Error in Schema Union with Optional and Transform Functions

What's wrong with that schema? I'm trying to make a schema that either takes an array of string directly, or creates one out of a comma-separated string (and gives an empty array when provided with a null or undefined value).

const myschema = S.Union(
  S.Array(S.String),
  S.optionalWith(S.split(','), {
    default: () => [],
    nullable: true,
  }),
);


I get the following error:

Diagnostics:
1. No overload matches this call.
     Overload 1 of 4, '(members_0: All, members_1: All, ...members: All[]): Union<readonly [All, All, ...All[]]>', gave the following error.
       Argument of type 'optionalWith<transform<SchemaClass<string, string, never>, Array$<typeof String$>>, { default: () => never[]; nullable: true; }>' is not assignable to parameter of type 'All'.
         Type 'optionalWith<transform<SchemaClass<string, string, never>, Array$<typeof String$>>, { default: () => never[]; nullable: true; }>' is missing the following properties from type 'Schema<never, never, unknown>': Type, Encoded, Context
     Overload 2 of 4, '(...members: readonly All[]): Schema<any, any, unknown>', gave the following error.
       Argument of type 'optionalWith<transform<SchemaClass<string, string, never>, Array$<typeof String$>>, { default: () => never[]; nullable: true; }>' is not assignable to parameter of type 'All'.
         Type 'optionalWith<transform<SchemaClass<string, string, never>, Array$<typeof String$>>, { default: () => never[]; nullable: true; }>' is missing the following properties from type 'Schema<never, never, unknown>': Type, Encoded, Context 
Was this page helpful?