react-admin
react-admin copied to clipboard
RA-OSS-20 - Some Inputs with choices in their props do not accept ReadonlyArray<T>
Fixes #9155
This code was written and reviewed by GitStart Community. Growing great engineers, one PR at a time.
Thanks for this updated version.
I must admit I'm a bit reluctant to accept this solution, because of all the as any[] it requires.
An alternative solution, that would be cleaner IMO, would be to use generic types in this manner:
interface ChoicesProps <T = any[]> {
choices?: T extends Array<any> ? T : T extends ReadonlyArray<any> ? T : "must be Array or ReadonlyArray";
}
However this would also require propagating the type to inner layers of the code. So it may lead to many changed files...
You can give it a try if you will, but I must remind that, for the reasons explained here, and because it is so easy to fix in user-land, we are not willing to invest too much time on resolving this issue in case it starts becoming too complex.
@slax57 we tried another fix can you check it out.