Shmew / Feliz.MaterialUI

Feliz-style Fable bindings for Material-UI
https://shmew.github.io/Feliz.MaterialUI/
MIT License
70 stars 19 forks source link

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

Closed Zaid-Ajaj closed 4 years ago

Zaid-Ajaj commented 4 years ago

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?

cmeeren commented 4 years ago

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!

cmeeren commented 4 years ago

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:

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.