Skip to content
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

Types are generally incompatible with ReadonlyArray #7656

Open
lukpsaxo opened this issue Jan 23, 2025 · 1 comment
Open

Types are generally incompatible with ReadonlyArray #7656

lukpsaxo opened this issue Jan 23, 2025 · 1 comment

Comments

@lukpsaxo
Copy link

Provide a general summary of the issue here

Props that take array's generally use the mutable form e.g. here the columns

https://github.com/adobe/react-spectrum/blob/main/packages/react-aria-components/src/Table.tsx#L529

🤔 Expected Behavior?

They instead be typed to take ReadonlyArray where the array is not mutated - that then allows the consumer to pass a mutable or a readonly array.

😯 Current Behavior

An error trying to assign a readonly array to a prop that takes a mutable array

Image

💁 Possible Solution

Updating alot of T[] -> ReadonlyArray<T>

🔦 Context

We use readonly arrays frequently to make sure no-one is mutating a value they shouldn't and causing a unintended side effect. The current design means we would need to add a typescript expect error to use readonly arrays or a cast.

🖥️ Steps to Reproduce

N/A

Version

N/A

What browsers are you seeing the problem on?

Other

If other, please specify.

No response

What operating system are you using?

N/A

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

@lukpsaxo
Copy link
Author

I can contribute PR's to update where and as it affects me but I'd like a response as to whether you would accept those first.

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

No branches or pull requests

1 participant