Syntax Lookup

Enter some language construct you want to know more about.
This is the @genType decorator.

The @genType decorator may be used to export ReScript values and types to JavaScript, and import JavaScript values and types into ReScript. It allows seamless integration of compiled ReScript modules in existing TypeScript, or plain JavaScript codebases, without losing type information across different type systems.

GenType is a code generation tool for automatically generating TypeScript type definitions, and JS runtime converters for non-shared ReScript values. It also features first-class support for rescript-react components.

Example

ReScriptTypeScript Output
@genType
export type color =
  | Red
  | Blue

@genType @react.component
export make = (~name: string, ~color: color) => {
  let colorStr = switch color {
  | Red => "red"
  | Blue => "blue"
  }
  <div className={"color-" ++ colorStr}> {React.string(name)} </div>
}

References