Open
Description
What you were expecting:
SelectInput
choices should accept ReadonlyArray<T>
What happened instead:
SelectInput
choices does not accept ReadonlyArray<T>
Steps to reproduce:
- use
"react-admin": "^4.12.3"
Related code:
- Preferably, a sandbox forked from
- L129
- L151
https://stackblitz.com/edit/github-h13gjc?file=src%2Fposts%2FPostEdit.tsx
- A link to a GitHub repo with the minimal codebase to reproduce the issue
import { SelectInput } from 'react-admin';
type Choice = {
id: number;
name: string;
};
const mutableArray = [
{
id: 1,
name: 'foo',
},
{
id: 2,
name: 'bar',
},
{
id: 3,
name: 'baz',
},
] satisfies Array<Choice>;
const readonlyArray = [
{
id: 1,
name: 'foo',
},
{
id: 2,
name: 'bar',
},
{
id: 3,
name: 'baz',
},
] as const satisfies ReadonlyArray<Choice>;
export const SelectInputGroup = () => {
return (
<>
<SelectInput source="mutableChoices" choices={mutableArray} />
<SelectInput source="immutableChoices" choices={readonlyArray} /> // type error
</>
);
};
Other information:
My suggestion (though more than just the SelectInput needs to be inspected):
- choices?: any[];
+ choices?: readonly any[]; // or ReadonlyArray<any>
Environment
- React-admin version: 4.12.3
- Last version that did not exhibit the issue (if applicable):
- React version: 18.2.0
- Browser: Google Chrome 115.0.5790.114 (Official Build) (arm64)
- Stack trace (in case of a JS error):
Metadata
Metadata
Assignees
Labels
No labels