Open sublimator opened 4 years ago
I like this idea a lot. Although I believe this already exists (sort of).
type A = {
B: {
C: [
{D: "E"}
]
}
}
type E = A extends {B: {C: [{D: infer E}]}} ? E : never;
If there was going to be a shorthand for generic type params, I'd think it would mirror destructuring (not GraphQL selection sets). Perhaps it could look like this.
type A = {
B: {
C: [
{D: "E"}
]
}
}
type X<{B: {C: {[infer D]}}} extends A> = D;
@harrysolovay
Neat! Yeah, the idea has a lot of appeal to me in the abstract, just not sure about the impl details.
People like you and the TS team boffins can think of something though :)
This might be a bit of a crazy idea, but here goes: to enable loose coupling between components we sometimes write Pick<Type, 'a' | 'b' | 'c'>
It would be nice if we could create a type query to select properties with a similar syntax to GraphQL:
e.g:
This would be equivalent to
How often would you do that in "the real world" ? definitely more often if you could How often should you do that? unclear ?
Some real-world code:
Pick<Response, 'ok' | 'json'>
could beResponse[{ok, json}]
edit: that's not a great example use case, cause you could just as well do
Partial<Response>