Docs / Language Manual / Use Illegal Identifier Names
Edit

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:

ReScriptJS Output
let \"my-🍎" = 10

type element = {
  \"aria-label": string
}

let myElement = {
  \"aria-label": "close"
}

let label = myElement.\"aria-label"

let calculate = (~\"Props") => {
  \"Props" + 1
}

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.