I'm looking to type a generic object and have properties of that object return in a typed array. The ability to get a singular typed property from an object is documented and works, however i'm unable to get this to work with an array. Seems the 'union type'.
// from the documentation
// @ http://www.typescriptlang.org/docs/handbook/advanced-types.html
function getProperty<T, K extends keyof T>(o: T, name: K): T[K] {
return o[name];
}
const a = getProperty(person, 'age');
// a: number
const n = getProperty(person, 'name');
// n: string
const getProperties = <T>(obj: T, keys: Array<keyof T>) => keys.map((arg) => getProperty(obj, arg));
const [a2, n2] = getProperties(person, ['name', 'age']);
// result:
// a2: string | number
// n2: string | number
// what i want:
// a2: string
// n2: number