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

Cannot assign readonly items to Grid and ComboBox #8327

Open
peholmst opened this issue Dec 11, 2024 · 4 comments
Open

Cannot assign readonly items to Grid and ComboBox #8327

peholmst opened this issue Dec 11, 2024 · 4 comments
Labels
DX Developer experience issue refactor Internal improvement typescript TypeScript definitions issue vaadin-grid

Comments

@peholmst
Copy link
Member

It is currently not possible to assign a readonly array as items to a Grid or a ComboBox (or possibly the other selection components as well; I haven't tried). The following code:

const items: readonly string[] = ["hello", "world"];

export default function MyComponent() {
    return <div>
        <Grid items={items} >
        </Grid>
    </div>
}

Gives the following error:

TS4104: The type readonly string[] is readonly and cannot be assigned to the mutable type string[]

If I remove readonly, it works. Since the selection components are not editing their own items, I think it should not matter whether the array I pass in is readonly or not.

@web-padawan web-padawan transferred this issue from vaadin/react-components Dec 11, 2024
@web-padawan web-padawan added the typescript TypeScript definitions issue label Dec 11, 2024
@web-padawan
Copy link
Member

This should be addressed in the web components so I transferred the issue here.

Note, in the past there used to be a plan to make all data structures readonly but it was then discarded.
We have an issue from that time, see #2321, see also vaadin/platform#2371.

IMO this would be a breaking change since it's currently possible to use something like comboBox.items.push('Item') in the web component, although we don't really use this internally - I only found a few cases in vaadin-crud:

this.items.splice(this.items.indexOf(this.editedItem), 1);

We should investigate if there might be some other implications of using readonly items.
Also it would be good to have a list of components that would be affected by this change.

@peholmst
Copy link
Member Author

In case it is useful, the context in which I ran into this problem was when I tried to use a full-stack signal as an items source for a grid and a combo box. That was not possible because the value getter returned a read-only array.

@sissbruecker
Copy link
Contributor

Maybe we could do this to avoid breaking changes:

  get items(): TItem[] | null | undefined;
  set items(value: TItem[] | readonly TItem[] | null | undefined);

@yuriy-fix yuriy-fix added DX Developer experience issue vaadin-grid refactor Internal improvement needs discussion No decision yet, discussion needed labels Dec 12, 2024
@yuriy-fix
Copy link
Contributor

yuriy-fix commented Dec 12, 2024

This also might affect other properties apart from the items. For example, selectedItems. We probably need to list all of the components + props of array types before changing it.

@yuriy-fix yuriy-fix added needs research More information needed to estimate and removed needs discussion No decision yet, discussion needed needs research More information needed to estimate labels Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX Developer experience issue refactor Internal improvement typescript TypeScript definitions issue vaadin-grid
Projects
None yet
Development

No branches or pull requests

4 participants