Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 2592

How to write a typescript union-like

$
0
0

Yes. But string-unions are something that you typically only find in ReScript codebases when dealing with TypeScript libraries. As long as you can stay inside ReScript-Land you would just use

type either = One | Two

Alternatively, you can also use polymorphic variants (denoted by the #). They always compile to strings as long as they don’t have a payload. And the first character does not need to be uppercased.

type either = #one | #two | #"other-number"
let something: either = #one
// "one"

Viewing all articles
Browse latest Browse all 2592

Trending Articles