react-admin icon indicating copy to clipboard operation
react-admin copied to clipboard

RA-OSS-20 - Some Inputs with choices in their props do not accept ReadonlyArray<T>

Open gitstart opened this issue 2 years ago • 3 comments

Fixes #9155


This code was written and reviewed by GitStart Community. Growing great engineers, one PR at a time.

gitstart avatar Aug 03 '23 12:08 gitstart

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 avatar Oct 26 '23 09:10 slax57

@slax57 we tried another fix can you check it out.

gitstart avatar Nov 08 '23 09:11 gitstart