title | description | canonical |
---|---|---|
Use Illegal Identifier Names | Handling (JS) naming collisions in ReScript | /docs/manual/v12.0.0/use-illegal-identifier-names |
Sometime, for e.g. a let binding or a record field, you might want to use:
- A capitalized name.
- A name that contains illegal characters (e.g. emojis, hyphen, space).
- A name that's one of ReScript's reserved keywords.
We provide an escape hatch syntax for these cases:
<CodeTab labels={["ReScript", "JS Output"]}>
let \"my-🍎"=10typeelement= { \"aria-label": string } letmyElement= { \"aria-label": "close" } letlabel=myElement.\"aria-label"letcalculate= (~\"Props") => { \"Props"+1 }
varmy$$unknown$unknown$unknown$unknown=10;varmyElement={"aria-label": "close"};varlabel=myElement["aria-label"];functioncalculate(Props){returnProps+1|0;}
See the output. Use them only when necessary, for interop with JavaScript. This is a last-resort feature. If you abuse this, many of the compiler guarantees will go away.