arktypea
arktypeβ€’9mo ago
ciscoheat

Empty string or number

I have this type that I want to reuse:

const number = type("string")
  .pipe((s) => s || "0")
  .to("string.numeric.parse");


I want to reuse it so if the string is empty, leave it as is, otherwise parse it as the number type.

But when I do this, it complains:

type("''").or(number); // An unordered union of a type including a morph and a type with overlapping input is indeterminate


This works though, so it's no big deal but just curious if it's possible to combine these above?

type("''").or("string.numeric.parse");
Was this page helpful?