rescript-lang / rescript

ReScript is a robustly typed language that compiles to efficient and human-readable JavaScript.
https://rescript-lang.org
Other
6.76k stars 449 forks source link

Explore record type extension #5659

Closed cristianoc closed 1 year ago

cristianoc commented 2 years ago

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

mununki commented 2 years ago

Another magic would solve the key props issue here 👍

cknitt commented 2 years ago

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

cristianoc commented 2 years ago

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.

mununki commented 2 years ago

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