I have a special function that takes in an array of strings and gives back an object where each string is a key with the value set as undefined
:
function getInitialCharacteristics(names: string[]): ??? {
return names.reduce((obj, name) => ({ ...obj, [name]: undefined }), {});
}
For example:
const result = getInitialCharacteristics(["hello", "world"]);
// result == { hello: undefined, world: undefined }
Now I'm curious about how to define the correct return type for getInitialCharacteristics
in TypeScript. It seems like using generics or generating the type dynamically could be the way to go. Is this achievable?