I’m trying to use a React component that has a property named type. ReScript won’t let me use that. I can only use type_. Here is my workaround. This works but I’d prefer not to use a reserved keyword.
I think the vs code extension automatically turned it into type_ not _type. Is this a bug? Actually I will check if I typed it wrong - not sure. Still don’t know why the decorator didn’t work. Finally I’m not sure what you’re describing is documented anywhere - I didn’t find it but did find the escape hatch mechanism for using keywords and the usage was discouraged- hence my question on this forum. Something needs improvement here.
There should probably be another note on using _type in scenarios where you want to compile to type instead here… gonna need a new issue on the documentation issue tracker.
it’s not a bug, it just happens to be a confusing convention for the following reasons:
_something is usually a convention for explicitly ignoring unused binding warnings
type_ is our recommendation whenever you insist on using a keyword, because it doesn’t collide with behavior 1)… but this doesn’t do any special transformations to the final JS output
The @react.component transformation implemented some custom behavior for transforming ~_xyz to a JS equivalent of xyz.
Additionally, there’s also a specific name mangling ruleset that was implemented for structural objects… the docs for that were removed for reasons I don’t know, but they are still there in the older v8 docs: Use Illegal Identifier Names | ReScript Language Manual
It’s definitely not the easiest to understand part of the language. Since it’s inherently weird, I am not sure how to document it properly nowadays.
The decorators only work on record attributes — not on labeled arguments, nor on structural object attributes (@react.component annotated make functions turn labeled arguments into a structural object).