Non-inline polymorphic variant?

is there any reason @unwrap myType is not allowed, given that the docs say [] poly variants are closed (and @unwrap's error says they must be closed poly variants?)

(btw i do know the error says it must be inline, i’m asking whether that is required for whatever reason)

on a side note, i think it’d be nice to have more warnings for @unwrap in the wrong position - e.g. in the return type of an external method

1 Like

Coming across this months later from a search. In case anyone else is searching in the future, here’s my two cents:

While it’s easy to @unwrap types going into JS, it’s hard reason about unwrapped types generally in ReScript, which is probably why it hasn’t been implemented.

Let’s say I wanted to bind to a JS function that returned what in TypeScript might be called a “union” type and then switch on that type. How would the switch be compiled to JS?

I could compare the properties available on the object in JS to the types available on the different ReScript types, but what if one or the other ReScript types is opaque? Or what if they don’t have different properties in ReScript and are just different constructors around the same kind of value?

I guess the easiest thing to do would be to require unwrappable types have to have unique constructors that take only values that are easily identifiable in JavaScript (string, null, undefined, array, etc.) But I think that would lead to confusing error messages and I think implementing the switch efficiently and JavaScript-readably would still be kind of hard.