Skip to content

Commit 7137766

Browse files
committed
Add open! docs
1 parent 7f3687c commit 7137766

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pages/docs/manual/latest/module.mdx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,23 @@ var p = School.getProfession(School.person1);
140140

141141
</CodeTab>
142142

143+
### Use `open!` to ignore shadow warnings
144+
145+
There are situations where `open` will cause a warning due to existing identifiers (bindings, types) being redefined. Use `open!` to explicitly tell the compiler that this is desired behavior.
146+
147+
```res
148+
let map = (arr, value) => {
149+
value
150+
}
151+
152+
// opening Js.Array2 would shadow our previously defined `map`
153+
// `open!` will explicitly turn off the automatic warning
154+
open! Js.Array2
155+
let arr = map([1,2,3], (a) => { a + 1})
156+
```
157+
158+
**Note:** Same as with `open`, don't overuse `open!` statements if not necessary. Use (sub)modules to prevent shadowing issues.
159+
143160
### Extending modules
144161

145162
Using `include` in a module statically "spreads" a module's content into a new one, thus often fulfill the role of "inheritance" or "mixin".

0 commit comments

Comments
 (0)