Closed
Description
openedon Feb 13, 2020
Search Terms
pick, nested, deep
Suggestion
Pick
can only be used to access properties at the top level of an object, it should support paths to get at more deeply nested values.
Use Cases
Typing form inputs from GraphQL fragments
Examples
type Company = {
id: number;
name: string;
address: {
id: number;
street: string;
city: string;
state: string;
};
}
You could then construct a new type as follows:
type FlatCompany = Pick<Company, "id" | "name" | { "addressId": ["address", "id"] }>
Which would yield:
type FlatCompany = {
id: number;
name: string;
addressId: number;
}
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment