Skip to content

Types are generally incompatible with ReadonlyArray #7656

Closed
@lukpsaxo

Description

@lukpsaxo

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions