Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stricter typing to from in useFragment #11487

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

samchungy
Copy link

@samchungy samchungy commented Jan 14, 2024

Optimises the type to infer the __typename of the TypedDocumentNode that is passed in. I don't think you would ever pass in a different __typename but happy to be corrected.

I wasn't sure if the TData extends { __typename?: string | undefined } logic belonged within StoreObject itself so I added another type to contain that logic.

Or possibly the type for from could be a Partial of TData?

Checklist:

  • If this PR contains changes to the library itself (not necessary for e.g. docs updates), please include a changeset (see CONTRIBUTING.md)
  • If this PR is a new feature, please reference an issue where a consensus about the design was reached (not necessary for small changes)
  • Make sure all of the significant new logic is covered by tests

Copy link

netlify bot commented Jan 14, 2024

‼️ Deploy request for apollo-client-docs rejected.

Name Link
🔨 Latest commit be233c9

Copy link

changeset-bot bot commented Jan 14, 2024

🦋 Changeset detected

Latest commit: 3952a5f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@apollo/client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@samchungy samchungy changed the title Optimise type Optimise useFragment from typing Jan 14, 2024
@samchungy samchungy changed the title Optimise useFragment from typing Add stricter typing to from in useFragment Jan 14, 2024
@phryneas
Copy link
Member

Hi there, thanks for the PR!

Could you please give an example where this is useful?

From reading the code changes, I have a rough idea on the intent, but tbh., I have the feeling that this might break some use cases with unions and interfaces, so we'll have to be very careful here.

@samchungy samchungy marked this pull request as draft January 29, 2024 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants