Effect CommunityEC
Effect Community17mo ago
4 replies
Thr1ve

Converting Nullish Fields to Optional in TypeScript

Is there a schema combinator/simple way to turn a "nullish" field into an "optional" one? (I'me fine just coercing
null
to
undefined
in this case)

Or, in code:
type From {
  // turn this
  foo?: string | undefined | null;
}

type To {
  // into this
  foo?: string | undefined;
}


I can imagine perhaps converting to a proper Option type and then back again...but surely there's a simpler way?
Was this page helpful?