id | keywords | name | summary | category | ||
---|---|---|---|---|---|---|
module-decorator |
|
@module |
This is the `@module` decorator. |
decorators |
The @module
decorator is used to bind to a JavaScript module.
<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");
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.