I have a set of storage properties:
interface StoredProps {
location: boolean;
notification: boolean;
}
I also get the strings representing the stored properties using keyof:
type StorableKeys = keyof StoredProps;
I have a function that can retrieve multiple stored properties at once:
const = getStoredProps<T extends StorableKeys[]>(keys: T) =>
keys.map(key => storage.get(key)).reduce((props, value, idx) => {
props[keys[idx]] = value;
return props;
}, {});
This works, however the return type is ultimately {}. I want the return type to match an object created by the keys.
I've tried using {} as { [M in keyof T]: T[M] }, but this doesn't work because T is an array type so this just ends up giving me an array type. I've also tried [M in T], but this is a syntax error.
Is there any way to derive a type from an array of property names?