Transforming a nullable string into a potentially undefined string
I’m trying to transform
string | undefined | null => string | undefined
string | undefined | null => string | undefined
I tried this:
pipe( S.nullish(S.string), S.transform( S.optional(S.string), s => s ?? undefined, identity ))
pipe( S.nullish(S.string), S.transform( S.optional(S.string), s => s ?? undefined, identity ))
But it chokes on
S.optional
S.optional
which is not a Schema but a PropertySignature
So I tried a union
pipe( S.nullish(S.string), S.transform( S.union(S.string, S.undefined), s => s ?? undefined, identity ))
pipe( S.nullish(S.string), S.transform( S.union(S.string, S.undefined), s => s ?? undefined, identity ))
Which works, however any downstream errors result in a bloated stack:
├─ Union member│ └─ Expected null, actual "https://example.com"├─ Union member│ └─ Expected undefined, actual "https://example.com"└─ Union member └─ ...
├─ Union member│ └─ Expected null, actual "https://example.com"├─ Union member│ └─ Expected undefined, actual "https://example.com"└─ Union member └─ ...
Firstly, am I transforming the schemas correctly? and if so, is there a way to suppress the messaging about nulls and undefined?