Getting the case class instead of the trait in dynRenderR

144 views Asked by At

I am working on a scalajs-react project, and I can't get the following to type check. The relevant documentation is here and here.


My pages are:

sealed trait Pages
case class Product(id: String) extends Pages

My routes are defined as:

dynamicRouteCT("#product" / string("[a-zA-Z0-9]+")
   .caseClass[Product]) ~> dynRenderR((page, ctl) => ProductPage(page, ctl))

The problem is that the dynRenderR component is returning a value of type Pages, when I really need a value of type Product in order to access the id property, which the Pages trait does not have.

The product page:

case class Props(routeData: Product, ctl: RouterCtl[Pages])

class Backend($: BackendScope[Props, Unit]) {
    def render(props: Props) = <.div("Product view " + props.routeData.id)
}

def apply(product: Product, ctl: RouterCtl[Pages]): ReactElement =
    component(Props(product, ctl))

private val component = ReactComponentB[Props]("Product")
    .renderBackend[Backend]
    .build

Strangely, this compiles and runs no problem; it is intellij which is complaining with:

Type mismatch, expected: Product, actual Pages

How can I modify or correctly utilize the dynRender component to pass a Product instead of a Pages, or can it not be used this way?

1

There are 1 answers

2
gzm0 On BEST ANSWER

Strangely, this compiles and runs no problem; it is intellij which is complaining [...]

Unfortunatley, Intellij's compilation/error reporting is not perfect, especially in presence of macros. While I don't know the details of scalajs-react, you can rest assured that if your code compiles and runs fine, you just see an Intellij bug.

So all you can do is:

  • Live with it or
  • file a bug.

Sorry I don't have better news.