Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax lookup: Open #315

Merged
merged 3 commits into from
May 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions misc_docs/syntax/language_open.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
id: "open"
keywords: ["open", "module"]
name: "open"
summary: "This is the `open` keyword."
category: "languageconstructs"
---

`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.

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.

### Example

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

```res
open Js.Math

// Use _PI and pow_float from the Js.Math module
let area = radius => _PI *. pow_float(~base=radius, ~exp=2.0)
```

```js
function area(radius) {
return Math.PI * Math.pow(radius, 2.0);
}
```

</CodeTab>

### References

* [Opening a module](/docs/manual/latest/module#opening-a-module)
* [Use open! to ignore shadow warnings](/docs/manual/latest/module#use-open-to-ignore-shadow-warnings)