Skip to content

allow mutation of private record fields with @allowMutation#8366

Open
tsnobip wants to merge 2 commits intomasterfrom
allow_mutation_private_record
Open

allow mutation of private record fields with @allowMutation#8366
tsnobip wants to merge 2 commits intomasterfrom
allow_mutation_private_record

Conversation

@tsnobip
Copy link
Copy Markdown
Member

@tsnobip tsnobip commented Apr 19, 2026

this PR allows this:

module Foo: {
  @allowMutation
  type t = private {
    mutable foo: int,
  }
  let make: int => t
} = {
  type t = {
    mutable foo: int,
  }
  let make = foo => {foo: foo}
}

let foo = Foo.make(10)

foo.foo = 5

Using private for records is very convenient to bind to JS classes so you can easily access properties and methods while preventing object creation. Though, before this PR, the mutation of fields marked as mutable inside private records was not possible and that is a common limitation inside WebAPI bindings, for DOM.node for example where textContent should be mutable.

@tsnobip tsnobip force-pushed the allow_mutation_private_record branch from 3a8f357 to 2bcf3f7 Compare April 19, 2026 09:43
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 19, 2026

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@8366

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@8366

@rescript/darwin-x64

npm i https://pkg.pr.new/@rescript/darwin-x64@8366

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@8366

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@8366

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@8366

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@8366

commit: 12f8390

should be reversed at some point to become the
default behavior you could opt-out with `@DisallowMutation`
@tsnobip tsnobip force-pushed the allow_mutation_private_record branch from f33af2d to 12f8390 Compare April 19, 2026 12:28
@tsnobip tsnobip force-pushed the allow_mutation_private_record branch from 12f8390 to 57f0c88 Compare April 19, 2026 12:40
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.

3 participants