Is it possible to convert this:
const readonlyArray: readonly ['a', 'b', 'c'] = ['a', 'b', 'c'] as const; type DesiredType = typeof readonlyArray[number]; to something like:
const array = ['a', 'b', 'c']; // this will come dynamically and sometimes it will be ['a', 'e', 'f'] const readonlyArray = array as const; type DesiredType = typeof readonlyArray[number]; I think this is not possible, but do you have a similar solution that will do the same work?
Here is the simplified version of the real world problem:
I have a React component with 2 props - status: 'a' | 'b', renamedPropB?: string and if you change the renamedPropB from undefined to let's say 'Z' the type of the status should become 'a' | 'Z' instead of the original 'a' | 'b'.
And the idea is to have the string literals in the union in an string array so it will be dynamic and easier to change the 'b' to 'Z' as well as to add more or remove existing string literals from the union.