Skip to content

Optional fields for record only work with variables but not expressions #5733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
4 of 5 tasks
TimonFlick opened this issue Oct 14, 2022 · 5 comments
Closed
4 of 5 tasks

Comments

@TimonFlick
Copy link

Using optional type for records with expression instead of variable does not work.

This is working:

let setDefaultOptions = (~newOptions: options) => {
  let weekStartOn = newOptions.weekStartOn->Option.map(Weekday.toInt)
  let options: options_ = {
    weekStartOn: ?weekStartOn,
  }
  setDefaultOptions_(~newOptions=options)
}

This is not working:

let setDefaultOptions = (~newOptions: options) => {
  let options: options_ = {
    weekStartOn: ?newOptions.weekStartOn->Option.map(Weekday.toInt),
  }
  setDefaultOptions_(~newOptions=options)
}

Thank you for filing! Check list:

  • Is it a bug? Usage questions should often be asked in the forum instead.
  • Concise, focused, friendly issue title & description.
  • A minimal, reproducible example.
  • OS and browser versions, if relevant.
  • Is it already fixed in master?
@cristianoc
Copy link
Collaborator

Have you tried putting it inside (parens) ?

@mununki
Copy link
Member

mununki commented Oct 14, 2022

?Option.map(newOptions.weekStartOn, Weekday.toInt),

It would work, I guess.

@vikfroberg
Copy link

Have you tried putting it inside (parens) ?

Yes we tried that. And for one, the formatter removed it. But we turned off the formatter and it still didn't work.

@cristianoc
Copy link
Collaborator

Would you try to install rescript@next? It might be this: https://github.com/rescript-lang/rescript-compiler/pull/5581/files

In which case, as a temporary workaround you can use the variable or avoid using ->.

@TimonFlick
Copy link
Author

?Option.map(newOptions.weekStartOn, Weekday.toInt),

It would work, I guess.

this works yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants