-
Notifications
You must be signed in to change notification settings - Fork 44
[Design] Allow renaming of exported component props. #75
Comments
One possibility is to write the explicitly curried version and add annotations to the function type, like this: [@genType]
let make =
[@genType.as "type"]
(
(~type_) =>
[@genType.as "$number"]
(
(~number, _children) => {
...component,
render: _self => {
Js.log2("type", type_);
Js.log2("$number", number);
<div />;
},
}
)
); |
Another possibility is to use a map-style annotation: module Design2 = {
[@genType.as [("type_", "type"), ("number", "$number")]]
let make = (~type_, ~number, _children) => {
...component,
render: _self => {
Js.log2("type", type_);
Js.log2("$number", number);
<div />;
},
};
}; One downside here is that it's possible to misspell the matching between One downside of the annotation on the uncurried function is that first, the uncurried version needs to be used, and second, there's the convention that the annotation refers to the first named argument in the rest of the type. These are all extra details that one would need to learn. |
One advantage of the map notation |
@IwanKaramazow @jchavarri is there a reason why annotations are not allowed inside here: |
Defining directly a type with annotated labeled arguments works. But defining a function does not seem to work. The AST seems to only have empty strings corresponding to named argument types. See: #75.
There's something strange going on. [@genType]
type functionTypeWithGenTypeAs =
[@genType.as "type"] (
(~type_: string) => [@genType.as "$number"] ((~number: int) => int)
); But if a function is annotated as below, only empty strings are picked up associated to the /* These genType.as annotation are currently not picked up in the AST */
[@genType]
let make =
[@genType.as "type"]
(
(~type_) =>
[@genType.as "$number"]
(
(~number, _children) => {
...component,
render: _self => {
Js.log2("type", type_);
Js.log2("$number", number);
<div />;
},
}
)
);
}; See 732bc24. |
Support renaming of the form `[@genType.as “xRenamed”] (~x) => …`. There’s a bug in ocaml 4.03.2 where the first annotation is lost. So it’s not possible to rename the first named argument. This limitation will go away once the compiler version is upgraded. See #75.
Added support for the annotation on the uncurried form in 732bc24. There's a bug in ocaml 4.03.2 where the first argument of the function can't be renamed. This will go away after the compiler upgrade. In future, refmt could make this look nicer. Already now, this is supported: [@genType]
let renameABunch = ~pad =>
[@genType.as "xRenamed"] (~x) => [@genType.as "yRenamed"] (~y) => pad+x+y; and is currently formatted to: let renameABunch = ~pad =>
[@genType.as "xRenamed"]
((~x) => [@genType.as "yRenamed"] ((~y) => pad + x + y)); Ideally, it could look like this: [@genType]
let renameABunch = (~pad, [@genType.as "xRenamed"] ~x, [@genType.as "yRenamed"] ~y) => pad + x + y; |
The first solution is now in master. |
This is awesome!! 👏 🎉 |
Renaming in type definitions is already supported with
@genType.as
, for example:One would like to do the same when exporting components:
however it's not possible to add annotations next to named arguments above.
The text was updated successfully, but these errors were encountered: