Syntax Lookup

Enter some language construct you want to know more about.

@unboxed

This is the @unboxed decorator.

The @unboxed decorator provides a way to unwrap variant constructors that have no overlap in their runtime representation, or record objects that have a single field.

Example

ReScriptJS Output
@unboxed
type listItemValue = String(string) | Boolean(bool) | Number(float)
let myArray = [String("Hello"), Boolean(true), Boolean(false), Number(13.37)]

@unboxed
type greeting = {message: string}
let hi = {message: "hello!"}

@unboxed for variants with multiple constructors is available since ReScript 11.0.0.

ReScript 12 adds runtime discrimination for ArrayBuffer.t, DataView.t, and typed array payloads. ReScript 12.1 also supports Set.t, Map.t, WeakSet.t, and WeakMap.t. Each distinct JavaScript built-in can occupy its own constructor without overlapping the others.

References