Skip to content

Commit 9cbd043

Browse files
committed
remove old example
1 parent 9041cbd commit 9cbd043

File tree

1 file changed

+0
-39
lines changed

1 file changed

+0
-39
lines changed

markdown-pages/docs/manual/null-undefined-option.mdx

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -126,45 +126,6 @@ compiles to `undefined`! If you've got e.g. a string in JavaScript that you know
126126

127127
### Caveat 1
128128

129-
The option-to-undefined translation isn't perfect, because on our side, `option` values can be composed:
130-
131-
<CodeTab labels={["ReScript", "JS Output"]}>
132-
133-
```res example
134-
let x = Some(Some(Some(5)))
135-
```
136-
137-
```js
138-
var x = 5;
139-
```
140-
141-
</CodeTab>
142-
143-
This still compiles to `5`, but this gets troublesome:
144-
145-
<CodeTab labels={["ReScript", "JS Output"]}>
146-
147-
```res example
148-
let x = Some(None)
149-
```
150-
151-
```js
152-
var Caml_option = require("./stdlib/caml_option.js");
153-
154-
var x = Caml_option.some(undefined);
155-
```
156-
157-
(See output tab).
158-
159-
</CodeTab>
160-
161-
What's this `Caml_option.some` thing? Why can't this compile to `undefined`? Long story short, when dealing with a polymorphic `option` type (aka `option<'a>`, for any `'a`), many operations become tricky if we don't mark the value with some special annotation. If this doesn't make sense, don't worry; just remember the following rule:
162-
163-
- **Never, EVER, pass a nested `option` value (e.g. `Some(Some(Some(5)))`) into the JS side.**
164-
- **Never, EVER, annotate a value coming from JS as `option<'a>`. Always give the concrete, non-polymorphic type.**
165-
166-
### Caveat 2
167-
168129
Unfortunately, lots of times, your JavaScript value might be _both_ `null` or `undefined`. In that case, you unfortunately can't type such value as e.g. `option<int>`, since our `option` type only checks for `undefined` and not `null` when dealing with a `None`.
169130

170131
#### Solution: More Sophisticated `undefined` & `null` Interop

0 commit comments

Comments
 (0)