You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pages/docs/manual/latest/import-from-export-to-js.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -76,7 +76,7 @@ var paddedResult = LeftPad("hi", 5);
76
76
77
77
Depending on whether you're compiling ReScript to CommonJS or ES6 module, **this feature will generate subtly different code**. Please check both output tabs to see the difference. The ES6 output here would be wrong!
Copy file name to clipboardExpand all lines: pages/docs/manual/latest/pattern-matching-destructuring.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -747,7 +747,7 @@ Here are some advices.
747
747
748
748
Do not abuse the wildcard `_` too much. This prevents the compiler from giving you better exhaustiveness check, which would be especially important after a refactoring where you add a new case to a variant. Try only using `_` against infinite possibilities, e.g. string, int, etc.
749
749
750
-
Use `when` clause sparingly.
750
+
Use `if` clause sparingly.
751
751
752
752
**Flatten your pattern-match whenever you can**. This is a real bug remover. Here's a series of examples, from worst to best:
Copy file name to clipboardExpand all lines: pages/docs/manual/latest/shared-data-types.mdx
+3-4Lines changed: 3 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,15 +22,14 @@ Unlike most compiled-to-js languages, in ReScript, **you don't need to write dat
22
22
- Object. ReScript objects are JavaScript objects, vice-versa.
23
23
- Function. They compile to clean JS functions.
24
24
- Module. ReScript files are considered top-level modules, and are compiled to JS files 1 to 1. Nested modules are compiled to JavaScript objects.
25
-
- Unit. The `unit` type, which has a single value `()`, compiles to `undefined` too. Likewise, you can treat an incoming JS `undefined` as `()`.
26
-
27
-
<!--TODO:talkaboutpolyvariant-->
25
+
- Polymorphic variants.
26
+
- Unit. The `unit` type, which has a single value `()`, compiles to `undefined` too. Likewise, you can treat an incoming JS `undefined` as `()` if that's the only value it'll ever be.
28
27
29
28
**Types that are slightly different than JS, but that you can still use from JS**:
30
29
- Int. **Ints are 32-bits**! Be careful, you can potentially treat them as JS numbers and vice-versa, but if the number's large, then you better treat JS numbers as floats. For example, we bind to Js.Date using `float`s.
31
30
- Option. The `option` type's `None` value compiles into JS `undefined`. The `Some` value, e.g. `Some(5)`, compiles to `5`. Likewise, you can treat an incoming JS `undefined` as `None`. **JS `null` isn't handled here**. If your JS value can be `null`, use [Js.Nullable](api/js/nullable) helpers.
- Variant. Check the compiled JavaScript output of variant to see its shape. We don't recommend exporting a ReScript variant for pure JS usage, since they're harder to read as plain JS code, but you can do it.
0 commit comments