Suppose I have an object with a static set of keys, and then a type specifying a subset of those keys as a static array:
const myBigStaticObject = {
key1: () => 'foo',
key2: () => 'bar',
// ...
keyN: () => 'fooN',
}
type BigObject = typeof myBigStaticObject
type Keys = ['key2', 'keyN']
Is there a nice way of then programmatically creating a mapped type which takes Keys as its generic argument, i.e. does the following:
type ObjectValueFromKeys<K extends (keyof BigObject)[]> = // ???
// such that:
ObjectValueFromKeys<Keys> = [() => 'bar', () => 'fooN']
The equivalent for objects here would be:
const objectKeys = {
a1: 'key2';
a2: 'keyN';
}
type ObjectValueFromObjectKeys<M extends Record<string, keyof BigObject>> = {
[K in keyof M]: BigObject[M[K]]
}
// then
type ObjectValueFromObjectKeys<typeof objectKeys> = {
a1: () => 'bar';
a2: () => 'fooN';
}