rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

Explore record type extension

Open cristianoc opened this issue 1 year ago • 1 comments

type extended = {...t, x:string} as an abbreviation instead of repeating the field of the type definition of t.

cristianoc avatar Sep 13 '22 04:09 cristianoc

Another magic would solve the key props issue here 👍

mununki avatar Sep 13 '22 13:09 mununki

This would be so great for the React Native bindings!

Currently the props of View need to be repeated for all subclasses of View, see e.g. https://github.com/rescript-react-native/rescript-react-native/blob/4f04d7788829f4764ca570ec3920f24b8c149568/src/components/Slider.res#L21.

Having

module Slider = {
  type props = {
    ...View.props,
    disabled?: bool,
    maximumTrackImage?: bool,
    // ... more slider props ...
  }

  @module("react-native")
  external make: props => React.element = "Slider"
}

instead would be a huge win!

/cc @MoOx

cknitt avatar Sep 22 '22 06:09 cknitt

I wish we could extend the parse tree and this would be some clean extension. Instead, one would have to find a representation using the existing AST. For instance, a fake field called "...". Other than that, the type checking extension should not be difficult.

cristianoc avatar Sep 22 '22 06:09 cristianoc

~~Not sure, but isn't it workable with label_declaration and attribute something @spread?~~ Deleted a confused comment.

mununki avatar Sep 22 '22 11:09 mununki