Skip to content

Allow For to accept readonly arrays - #950

Merged
JoviDeCroock merged 1 commit into
preactjs:mainfrom
joeyTedeschi:accept-readonly-for-each
Jul 6, 2026
Merged

Allow For to accept readonly arrays#950
JoviDeCroock merged 1 commit into
preactjs:mainfrom
joeyTedeschi:accept-readonly-for-each

Conversation

@joeyTedeschi

@joeyTedeschi joeyTedeschi commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Expand <For> accepted list types to ReadonlyArray<T> for direct arrays, signals, readonly signals, and function-returned list sources
  • Keep Preact and React utility implementations in sync
  • Add browser utility tests for direct readonly arrays, signal<readonly T[]>, and computed readonly signals
  • Add a patch changeset for @preact/signals and @preact/signals-react

Without this change, attempting to use a readonly array with For results in a TS 2322 (due to assigning readonly T[] to T[]).

PR was created in collaboration with AI (Codex GPT 5.5), which was used to generate the .changeset/readonly-for-inputs.md and unit tests. PR was opened in draft, manually audited, and then opened for wider review

@changeset-bot

changeset-bot Bot commented Jul 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1cf30c4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@preact/signals Patch
@preact/signals-react Patch
preact-signals-devtools Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify

netlify Bot commented Jul 6, 2026

Copy link
Copy Markdown

Deploy Preview for preact-signals-demo ready!

Name Link
🔨 Latest commit 1cf30c4
🔍 Latest deploy log https://app.netlify.com/projects/preact-signals-demo/deploys/6a4bed5ab29925000816ba08
😎 Deploy Preview https://deploy-preview-950--preact-signals-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Show.displayName = "Show";

type ForEach<T> =
| ReadonlyArray<T>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that we'd now accept normal arrays as a valid type as well. The const list + listValue logic already supported, but is there a concern with supporting it explicitly?

@joeyTedeschi
joeyTedeschi marked this pull request as ready for review July 6, 2026 18:32
@JoviDeCroock
JoviDeCroock merged commit 76f9155 into preactjs:main Jul 6, 2026
6 checks passed
@github-actions github-actions Bot mentioned this pull request Jul 6, 2026
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