Field spread vs optional fields?

Hi Folks
I have noticed some strange behavior around this situation… if I write a simple function to pluck an optional field from a record, the types dont line up: I expect the result of the plucked function to be option

Thanks,
A

https://rescript-lang.org/try?version=v10.1.2&code=C4TwDgpgBMULxQN4CgowBYEsB2BzA-AFxQ6zIC+yyANhLAB7xQAUiwWe5AlPAHwY5cNOlBBNmwYsB5x+wAHTtBVWrEkwmiSsLXpGCehK46MYhCCMqR+jIwDUUAIwmzpqA8dA

You can use question mark to get the optional value. But I agree, I was also confused by the behaviour.

https://rescript-lang.org/try?version=v10.1.2&code=C4TwDgpgBMULxQN7ABYEsB2BzA-ALik2AF8AoUgGwlgA94oAKRHVTLYgSngD4Z1sAtNwBCECsAB0AeTDA0AewwSs1AOppUAEQgAzAIYBXcQwCMHStSgh6DYAWBc4vSa0EixkmXMXK1GlNr6RsCm5hawdjD0iGThfHQINLbmVBEo1gggyeSpUAnxUADUUCZxGXzWxaVAA

What’s happening in this case is that you basically only take into account the case where thing is not None, you don’t have an exhaustive pattern match and the compiler warns you about it.

1 Like

breaking equivalence betweeen {thing} and t.thing is a burden still. IMO. I can work through the exception, but it gives a bad experience.

It can be confusing the first time, but the alternative has bigger issues.