I'd like to use this array with a union type, but TS rightly assumes that its type is string: "Argument of type 'string' is not assignable to parameter of type '"a" | "b"'."
function doSomething(value: "a" | "b"){}
["a", "b"].map(e => doSomething(e));
Is there a ways in which I can define the types of the array elements? If not, is there another way to solve this problem? I do not want to cast it in map().
constassertion to tell the compiler to infer a more specific type for["a", "b"], like this. Does that meet your needs or is there some issue with it?