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

How to write a typescript union-like

$
0
0

Is this the right way to write a type that can only take 2 strings? Like a typescript union.

type EitherOne = "one" | "two";
const thatOne: EitherOne = "one";

I’m asking because, I didn’t find this easily.
Is that a type annotation?

type either =
  | @as("ONE") One
  | @as("TWO") Two
let something: either = One
let somethingElse: either = Two

Viewing all articles
Browse latest Browse all 2592

Trending Articles