Skip to content

Commit b8c596d

Browse files
authored
Merge pull request #315 from kevanstannard/syntax-lookup-open
Syntax lookup: Open
2 parents 01cc6cd + be98ae6 commit b8c596d

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 expose all values, types, modules, etc of a module in the current scope. This is useful whenever you want to use a module's functionality without typing out the module name over and over again.
10+
11+
In some cases, `open` will cause a "shadow warning" due to existing identifiers and types being redefined by an `open`ed module. You can explicitly ignore that warning by using an `open!` statement instead.
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)