Typescript: convert array of strings to readonly array of literals

Viewed 392

Is there any possibility to convert already defined array of strings (string[]) to readonly array of literals?

Something like:

const arr = ["a", "b"]
const readonlyArr = arr as const

(which doesnt work of course)

I know, that const readonlyArr = ["a", "b"] as const works, but thats not what i want...

Thanks!

0 Answers
Related