Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

jsx: allow locally abstract types and type constraints on @react.component #490

Merged
merged 3 commits into from
May 11, 2022

Conversation

glennsl
Copy link
Contributor

@glennsl glennsl commented May 8, 2022

This is a continuation of #487 that fixes the type annotations for locally abstract types. Because locally abstract types can't be defined in type annotations, they have to be replaced with plain type variables, and this has to be done recursively since they can occur anywhere in a type.

The only limitation I have intentionally imposed here is that extensions are not allowed in type annotations when locally abstract types are used, because that would require traversal of the entire AST, which is no fun.

As requested, here's a complete example:

module type Show = {
  type t
  let show: t => string
}

module Int = {
  type t = int
  let show = string_of_int
}

module Thing = {
  @react.component
  let make = (type a, ~model as module(Model: Show with type t = a), ~value: a) =>
      <div> {value->Model.show->React.string} </div>
}

let make = () =>
  <Thing model=module(Int) value=42 />

I hope this one covers all the bases :)

…onent

* jsx: allow locally abstract types in @react.component definitions

* jsx: allow type constraints on @react.componenet definitions
@cristianoc
Copy link
Contributor

Looks good to me.
Leaving for @IwanKaramazow to take a final look.

@cristianoc cristianoc merged commit da10fed into rescript-lang:master May 11, 2022
@glennsl glennsl deleted the fix/jsx/newtype-type-error branch May 11, 2022 06:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants