Skip to content

Files

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Latest commit

a13044c · Jun 2, 2024

History

History
57 lines (38 loc) · 1.26 KB

decorator_module.mdx

File metadata and controls

57 lines (38 loc) · 1.26 KB
id keywords name summary category
module-decorator
module
decorator
@module
This is the `@module` decorator.
decorators

The @module decorator is used to bind to a JavaScript module.

Example

<CodeTab labels={["ReScript", "JS Output"]}>

@module("path")
external dirname: string => string = "dirname"

let root = dirname("/User/github")
var Path = require("path");

var root = Path.dirname("/User/github");

Import Attributes

Since 11.1

@module also supports import attributes. It looks like this:

<CodeTab labels={["ReScript", "JS Output (Module)"]}>

@module({from: "./myJson.json", with: {type_: "json", \"some-exotic-identifier": "someValue"}})
external myJson: JSON.t = "default"

Console.log(myJson)
import MyJsonJson from "./myJson.json" with {"type": "json", "some-exotic-identifier": "someValue"};

var myJson = MyJsonJson;

console.log(myJson);

More information in the dedicated documentation for import attributes.

References