rescript-lang / rescript-compiler

The compiler for ReScript.
https://rescript-lang.org
Other
6.68k stars 445 forks source link

class are being removed when migrating .re to .res #5104

Closed MoOx closed 3 years ago

MoOx commented 3 years ago

Thank you for filing! Check list:

How to reproduce?

Use this

class type virtual materialTopTabBarProps = {
    as 'self;
    constraint 'self = #materialTopTabBarOptions;
    pub state: navigationState(M.params);
    pub navigation: navigation;
    pub descriptors: descriptors;
    // SceneRendererProps from react-native-tab-view
    pub layout: layout;
    pub position: animatedNode;
    pub jumpTo: string => unit;
  };

Try using bsc -format. The code just disappear. You can reproduce on the playground too (select .RE, paste the snippet, click on .RES, no more class).

This is a problem for rescript-react-navigation as we have a lot of class to bind.

flash-gordon commented 3 years ago

Support for ocaml style classes was removed in 9.1. I wonder if they are truly necessary for the bindings, though.

bobzhang commented 3 years ago

hi @MoOx technically we did not remove class types, it is not exposed in rescript syntax though, so you don't need rush to convert such piece of code if you are busy, but you are suggested to migrate away from class types later.

Note in the latest release, you can compose structural types using object types (without need class types)

type small = {
   "x" : int 
}
type big = {
   ... small, "y" : int
}

let me know if you find something not expressible using object types

MoOx commented 3 years ago

To be honest, I don't see any real reason to use class. I will just convert to record and use @send if necessary.