Skip to content

Update 2023-05-17-enhanced-ergonomics-for-record-types.mdx #689

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 2 commits into from
May 22, 2023

Conversation

cristianoc
Copy link
Contributor

Sure, here's a draft for the documentation change that should make it more clear:


Title: Correction of Record Type Spread Behavior in ReScript v11 Documentation

Change:

Update the section "Record Type Spread" to clarify that fields from different record types cannot share the same name, even if they are of the same type.

Proposed Changes:

Under the section "Record Type Spread", modify the paragraph:

"Keeping it as straightforward as possible, type spreads are essentially a 'copy-paste' operation for fields from one or more records to another, inlining the fields from the spread records into the new record. Please note: As for right now it is not possible to override fields in the target record type."

To:

"Keeping it as straightforward as possible, type spreads are essentially a 'copy-paste' operation for fields from one or more records to another, inlining the fields from the spread records into the new record. Please note: it is not allowed to have fields with the same name in the records being spread, even if they are of the same type. Additionally, it is currently not possible to override fields in the target record type."


Reason for the change:

The previous text can lead to confusion, as it could be interpreted that fields with the same name but of the same type can be spread into a new record type. The proposed change provides clarification on this behavior to avoid such misunderstanding.


You can now create a PR on GitHub using this draft.

Sure, here's a draft for the documentation change that should make it more clear:

---

### Title: Correction of Record Type Spread Behavior in ReScript v11 Documentation

**Change:**

Update the section "Record Type Spread" to clarify that fields from different record types cannot share the same name, even if they are of the same type.

**Proposed Changes:**

Under the section "Record Type Spread", modify the paragraph:

"Keeping it as straightforward as possible, type spreads are essentially a 'copy-paste' operation for fields from one or more records to another, inlining the fields from the spread records into the new record. Please note: As for right now it is not possible to override fields in the target record type."

To:

"Keeping it as straightforward as possible, type spreads are essentially a 'copy-paste' operation for fields from one or more records to another, inlining the fields from the spread records into the new record. Please note: it is not allowed to have fields with the same name in the records being spread, even if they are of the same type. Additionally, it is currently not possible to override fields in the target record type."

---

**Reason for the change:**

The previous text can lead to confusion, as it could be interpreted that fields with the same name but of the same type can be spread into a new record type. The proposed change provides clarification on this behavior to avoid such misunderstanding.

---

You can now create a PR on GitHub using this draft.
In this discussion, we sought to clarify the semantics of record type spreading in ReScript v11 as described in the provided documentation. There was a particular focus on the treatment of optional fields when they are spread from one record into another, and how to appropriately phrase this in the documentation.

Key conclusions are:

1. **Record type spread**: The operation is fundamentally a 'copy-paste' mechanism that inlines fields from one or more records into a new record. All properties of the fields (including whether they're optional or mandatory) are preserved in the process.

2. **Unique field names**: Duplicate field names are not allowed across the records being spread, even if the fields share the same type.

3. **Phrasing in the documentation**: In order to reduce confusion and provide clear, concise information, it's recommended to phrase the explanation as follows:

    "Record type spreads act as a 'copy-paste' mechanism for fields from one or more records into a new record. This operation inlines the fields from the spread records directly into the new record definition, while preserving their original properties, such as whether they are optional or mandatory. It's important to note that duplicate field names are not allowed across the records being spread, even if the fields share the same type."

These conclusions should aid in improving the clarity and accuracy of the documentation, ensuring it provides an accurate representation of the semantics of record type spreading in ReScript v11.
@cristianoc cristianoc merged commit 67524c2 into master May 22, 2023
@cristianoc cristianoc deleted the record_spread branch May 22, 2023 01:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants