I want to write a array to object function, which extracts one property as the index, like:
export const arrayToObject
= <T, K extends keyof T, V extends T[K] & string>(arr: T[], key: K): { [v: V]: T } =>
Object.assign({}, ...arr.map(item => ({[item[key]]: item})));
But it gives a compile error saying An index signature parameter type must be 'string' or 'number' for V, although I constraint the V type to be string. Why is the error and what is the proper way to do it?