Let's say I have a list of strings
const arr = ["a", "b", "c"];
How exactly do I convert it to an object in such a way that these values will be a key to any object?
const obj = {
a: "can be anything",
b: 2,
c: 0
}
I have tried using
type TupleToObject<T extends readonly string[]> = {
[P in T[number]]: any;
};
but it doesn't seemed to be strongly typed.
arris a constant does not mean that the elements within the array can't be changed. What would you expect to happen if, during runtime, someone appended"d"to the array? TypeScript has no runtime type checking, so the question as stated is a bit ambiguous in terms of the expected result.type keys = "a" | "b" | "c";and thenconst obj:Record<keys, unknown> = {