Something like this?
function find<T, K extends keyof T>(thing: T, filterProps: K[]) {
return thing as Pick<T, K>;
}
const ourUser: User = { name: 'John McClane', age: 44, jobTitle: 'Cop' };
const filteredUser = find(ourUser, ['name', 'age']); // Pick<User, "name" | "age">
filteredUser.name; // String
filteredUser.age; // Number
filteredUser.jobTitle; //error
Perhaps your version would "find" the thing
from within the function body, rather than have it passed it as an argument.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…