Feb 29, 2024

ReScript 11.1

Unleashing ReScript from React

ReScript Team
Core Development

A couple of weeks ago, the ReScript team released ReScript 11.0, which laid ground work for a lot of possible improvements to make it easier to interact with the JavaScript ecosystem.

This next minor has some wonderful additions to the ReScript toolbelt for you today.

To install, use your favorite package manager to install the new compiler release, e.g.:

SH
npm install rescript@11.1

Find a list of all the new features below:

Generic JSX transform

TODO

Tagged template literals

This release comes with support for tagged templates.

A tag function in JavaScript is a function that expects an array of strings and variadic parameters as input. Now it's possibe to bind to such functions with the new @taggedTemplate decorator:

ReScriptJS Output
// see https://bun.sh/docs/runtime/shell
type result = {exitCode: int}
@module("bun") @taggedTemplate
external sh: (array<string>, array<string>) => promise<result> = "$"

let filename = "index.res"
let result = await sh`ls ${filename}`

Of course you can also create your own tag functions in ReScript now as well, it is just a function with the following signature.

RESCRIPT
let myTagFunction : (array<string>, array<'param>) => 'output

Refer to the docs to find a detailed example.

Import attributes

Import attributes is a JS feature that is currently in standardization, but is already implemented by many JS tools. Now, ReScript supports it too, as long as the compiler is configured to output ES6.

ReScriptJS Output
@module({from: "./myJson.json", with: {type_: "json", \"some-identifier": "yep"}})
external myJson: Js.Json.t = "default"
Console.log(myJson)

@module({from: "./myCss.css", with: {type_: "css", \"some-identifier": "yep"}})
external buttonCss: string = "button"
Console.log(buttonCss)

Array spread syntax

The spread syntax, which was already supported for records and lists for a long time, now also supports arrays!

RESCRIPT
let animals = ["🐶", "🐱", "🐷"] let moreAnimals = [...animals, "🐔", "🐴", "🐮"]

Hyphens in JSX tag names

We lifted restrictions on JSX tag names. This means you no longer need to escape tag names that contain hyphens:

Previously:

RESCRIPT
let x = <\"custom-tag" /> let y = <Foo.\"custom-tag" />

Now:

RESCRIPT
let x = <custom-tag /> let y = <Foo.custom-tag />

Acknowledgements

Once again we want to thank everyone from the community who volunteered their precious time to support this project with contributions of any kind, from documentation, to PRs, to discussions in the forum. But especially we want to thank the following people, who helped landing this release:

@cknitt, @cometkim, @cristianoc, @diogomqbm, @kevinbarabash, @shulhi, @tsnobip, @zth.

That's it

We hope you enjoy the newest improvements as much as we do.

If you find any problems with this new release, make sure to report them here:

Want to read more?
Back to Overview