Skip to content

Commit 5047073

Browse files
committed
Syntax Lookup: Open
1 parent 8f54a33 commit 5047073

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

misc_docs/syntax/language_open.mdx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
id: "open"
3+
keywords: ["open", "module"]
4+
name: "open"
5+
summary: "This is the `open` keyword."
6+
category: "languageconstructs"
7+
---
8+
9+
`open` is used to "open" a module so we can refer to the module's contents without needing to prepending the module's name.
10+
11+
In some cases, `open` will cause a warning due to existing identifiers and types being redefined by the opened module. In these cases, we can use `open!` instead which will suppress the warnings.
12+
13+
### Example
14+
15+
<CodeTab labels={["ReScript", "JS Output"]}>
16+
17+
```res
18+
open Js.Math
19+
20+
// Use _PI and pow_float from the Js.Math module
21+
let area = radius => _PI *. pow_float(~base=radius, ~exp=2.0)
22+
```
23+
24+
```js
25+
function area(radius) {
26+
return Math.PI * Math.pow(radius, 2.0);
27+
}
28+
```
29+
30+
</CodeTab>
31+
32+
### References
33+
34+
* [Opening a module](/docs/manual/latest/module#opening-a-module)
35+
* [Use open! to ignore shadow warnings](/docs/manual/latest/module#use-open-to-ignore-shadow-warnings)

0 commit comments

Comments
 (0)