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

Switch path unexpected on optional record with optional fields

$
0
0

OK I think I understand, the issue is here:

  type settings<'item, 'compareValue, 'id> = {
    getCompareValue: getCompareValue<'item, 'compareValue>,
    initialValue?: option<choice<'id>>, // optional field with an optional value
    choices: array<choice<'id>>,
    defaultLabel?: option<string>, // optional field with an optional value
  }

What you actually want I think is this:

type settings<'item, 'compareValue, 'id> = {
    getCompareValue: getCompareValue<'item, 'compareValue>,
    initialValue?: choice<'id>, // optional field 
    choices: array<choice<'id>>,
    defaultLabel?: string, // optional field 
  }

When you do this:

let component = switch settings {
      | Some({choices, defaultLabel}) =>

You’re actually checking is defaultLabel is set in this record, even if it’s set as None.

Or maybe I didn’t understand your issue, then it’d be interesting to come up with a working example on the playground.


Viewing all articles
Browse latest Browse all 2592

Trending Articles