Shmew/Feliz.MaterialUI

Styles.makeStyles cannot infer that the default 'props should be unit

Closed this issue · 2 comments

The following doesn't compile

let useStyles = Styles.makeStyles <| fun theme ->
  {|
    root = Styles.create [
      style.height 48
      style.padding(0, 30)
    ]
  |}

unless it is actually used, I was trying to fix the compile error when I was defining the value but the workflow is that I use it somewhere and the compile error would go away. I guess it is OK but this is sub optimal UX. Would there be a way to make add an overload that by default returns a function that takes a unit instead?

Unfortunately that won't work.

If I have only the unit overload as a proper type member and the rest as extension members, it will resolve to the unit overload, but then it's fixed and later usage can't change it to non-unit.

If I have both the unit and the generic 'props overload as proper type members, overload resolution fails.

Further tips are welcome!

I think my previous comment was mistaken. I seem to have thought this was an overload resolution error. The actual compiler error is a value restriction error, because useStyles is a generic value whose type can't be inferred unless it's used somewhere.

There are two simple solutions/workarounds:

  • Use the defined useStyles hook in a component, as originally mentioned
  • Annotate it, i.e. let useStyles: MyProps -> _ = Styles.makeStyles ...

This has been mentioned in the makeStyles docs. Since the problem is only temporary and it's easy to workaround, as well as in lieu of better solutions, I'm closing this.