microsoft / microsoft/TypeScript

Type Selection Queries

Open
#41,109 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

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:

prop: AType[{a, b, c: { d }]

This would be equivalent to

prop: Pick<AType, 'a' | 'b'> & {c: Pick<AType['c'], 'd'>}

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:

    const testFetch = jest.fn()

    class TestOptions extends GraphQlClient.Options {
      public fetch = testFetch
    }
    const response: Pick<Response, 'ok' | 'json'> = {
      ok: true,
      async json() {
        return { data: { auth: { token: testToken } } }
      }
    }
    testFetch.mockResolvedValue(response)

Pick<Response, 'ok' | 'json'> could be Response[{ok, json}]

edit: that's not a great example use case, cause you could just as well do Partial<Response>

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by studying TypeScript's existing Pick and indexed-access type behavior, then compare the proposed nested selection syntax with GraphQL-style queries. Review the issue's examples and determine whether the feature has a clear use case and type-system design. Done would require an agreed syntax, semantics, and implementation plan rather than only an example transformation.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.