Skip to content

Update object mangling mention #708

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

Merged
Merged
Show file tree
Hide file tree
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
21 changes: 0 additions & 21 deletions pages/docs/gentype/latest/supported-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,6 @@ Since objects are immutable by default, their fields will be exported to readonl

It is possible to mix object and option types, so for example the ReScript type `{. "x":int, "y":option(string)}` exports to JS type `{x:number, ?y: string}`, requires no conversion, and allows option pattern matching on the ReScript side.

Object field names follow ReScript's mangling convention (so e.g. `_type` in ReScript represents `type` in JS):

```
Remove trailing "__" if present.
Otherwise remove leading "_" when followed by an uppercase letter, or keyword.
```

## Tuples

ReScript tuple values of type e.g. `(int, string)` are exported as identical JS values of type `[number, string]`. This requires no conversion, unless one of types of the tuple items does.
Expand Down Expand Up @@ -123,20 +116,6 @@ Function components are exported and imported exactly like normal functions. For
let make = (~name) => React.string(name);
```

For renaming, named arguments follow ReScript's mangling convention:

```
Remove trailing "__" if present.
Otherwise remove leading "_" when followed by an uppercase letter, or keyword.
```

For example:

```res
@genType
let exampleFunction = (~_type) => "type: " ++ _type
```

## Imported Types

It's possible to import an existing TS/Flow type as an opaque type in ReScript. For example,
Expand Down
10 changes: 6 additions & 4 deletions pages/docs/gentype/latest/usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,14 @@ type persons = array<person>;

## Renaming, @genType.as, and object mangling convention.

By default, entities with a given name are exported/imported with the same name. However, you might wish to change the appearence of the name on the JS side.

**NOTE:** Starting from ReScript 7.0.0, `@genType.as` on record fields will be discouraged,
as it incurs a runtime conversion cost. Instead `@bs.as` will be supported and incur zero cost.
as it incurs a runtime conversion cost. Use a runtime free `@as` instead.

**NOTE:** Starting from ReScript 11.0.0, the object mangling is removed.

By default, entities with a given name are exported/imported with the same name. However, you might wish to change the appearence of the name on the JS side.

For example, in case of a record field whose name is a keyword, such as `type`:
For example, to use a reserved keyword `type` as a record field:

```res
@genType
Expand Down