type TupleToObject<T extends readonly (keyof any)[]> = {
[K in T[number]]: K
}
type Enum<T> = T[keyof T];
const state = ['todo', 'in progress', 'completed'] as const;
function tupleToObject<T extends readonly (keyof any)[]>(data: T): TupleToObject<T>{
return data.reduce((result: any, v: keyof any) => {
result[v] = v;
return result;
}, {});
}
const GenState = tupleToObject(state);
console.log(GenState);
const myState1: Enum<typeof GenState> = GenState.completed;
const myState2: Enum<typeof GenState> = 'completed';
const myState3: Enum<typeof GenState> = 'hold';
const myState4: keyof typeof GenState = 'completed';