Generic typescript: Generic type from keyof T values
问题 How can I infer the result type (TTarget) from TSource and the given property names (keyof TSource)? I've the following function to copy defined properties to a new object: export declare type PropertyNamesOnly<T> = { [K in keyof T]: T[K] extends Function ? never : K }[keyof T]; CopyProps<TSource, TTarget>(source: TSource, ...props: PropertyNamesOnly<TSource>[]): TTarget { const result: any = {}; for (const prop of props) { result[prop] = source[prop]; } return result; } Now I can use it like