Union of literal types from an array of strings
Hi I'm looking for a way to generate a union type for every string in an array.
Let's say I have an array
As you can see it'll be a lot of work to do the typing if the number of items in the array keeps increasing (let's say like 100 items). I just want a union type that consists of the literal types of whatever strings that are in the array (in this case
Let's say I have an array
const sample = ["apple", "banana", "grape", "orange""]. Basically I want to be able to get type SomeType = "apple" | "banana" | "grape" | "orange". I need this SomeType because I need to create a function that accepts one of these values instead of typing them one by one like thisAs you can see it'll be a lot of work to do the typing if the number of items in the array keeps increasing (let's say like 100 items). I just want a union type that consists of the literal types of whatever strings that are in the array (in this case
sample). How can I do this in typescript?