Can a struct be selected in a way that the type checker can handle without any issues?
Coming from TypeScript:
// Assuming a main object type with all fields:
interface User {
id: number;
name: string;
password: string;
};
// Using a picked type to pick only specific fields:
const get_all_users = (): Pick<User, 'id' | 'name'>[] => {/*...*/};
The Pick
type allows tsc to accept this:
const picked_user: Pick<User, 'id' | 'name'> = user;
Is there a feature in any crate/language that I might be overlooking? My concern is avoiding explicitly naming the struct, like UserPicked
, which can become cumbersome when there are numerous picked variations.