Skip to content

Commit 1b9462f

Browse files
authored
Tweak @bs.obj example (#279)
1 parent 42e0a81 commit 1b9462f

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

pages/docs/manual/latest/generate-converters-accessors.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ As in similar use-cases before, you can also use `@bs.deriving({jsConverter: new
298298

299299
## Convert Record Type to Abstract Record
300300

301-
> **Note**: For ReScript >= v7, we recommend using [plain records to compile to JS objects](bind-to-js-object#bind-to-record-like-js-objects).
302-
> This feature might still be useful for certain scenarios, but the ergonomics might be worse
301+
> **Note**: For ReScript >= v7, we recommend using [plain records to compile to JS objects](bind-to-js-object#bind-to-record-like-js-objects).
302+
> This feature might still be useful for certain scenarios, but the ergonomics might be worse
303303
304304
Use `@bs.deriving(abstract)` on a record type to expand the type into a creation, and a set of getter / setter functions for fields and methods.
305305

@@ -578,7 +578,7 @@ For example, suppose you need a JavaScript object like this:
578578

579579
```js
580580
var homeRoute = {
581-
method: "GET",
581+
type: "GET",
582582
path: "/",
583583
action: () => console.log("Home"),
584584
// options: ...
@@ -590,7 +590,7 @@ But only the first three fields are required; the options field is optional. You
590590
```res
591591
@bs.obj
592592
external route: (
593-
~_method: string,
593+
~\"type": string,
594594
~path: string,
595595
~action: list<string> => unit,
596596
~options: {..}=?,
@@ -600,15 +600,15 @@ external route: (
600600

601601
**Note**: the ` = ""` part at the end is just a dummy placeholder, due to syntactic limitations. It serves no purpose currently.
602602

603-
This function has four labelled parameters (the fourth one optional), one unlabelled parameter at the end (which we mandate for functions with [optional parameters](function#optional-labeled-arguments), and one parameter (`_method`) that requires an underscore prefix to avoid confusion with the ReScript keyword `method`.
603+
This function has four labelled parameters (the fourth one optional), one unlabelled parameter at the end (which we mandate for functions with [optional parameters](function#optional-labeled-arguments), and one parameter (`\"type"`) that required quoting to [avoid clashing](use-illegal-identifier-names) with the reserved `type` keyword.
604604

605605
Also of interest is the return type: `_`, which tells ReScript to automatically infer the full type of the JS object, sparing you the hassle of writing down the type manually!
606606

607607
The function is called like so:
608608

609609
```res
610610
let homeRoute = route(
611-
~_method="GET",
611+
~\"type"="GET",
612612
~path="/",
613613
~action=_ => Js.log("Home"),
614614
(),

0 commit comments

Comments
 (0)