Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

[experimental] Cannot infer fragment type from query #157

@janicduplessis

Description

@janicduplessis

Not sure if this is a limitation of typescript but it seems like it cannot infer fragment types from a query response.

const data = useLazyLoadQuery<SubmitTagsScreenQuery>(graphql`
    query SubmitTagsScreenQuery {
      viewer {
        ...SubmitTagsScreen_viewer
      }
    }
  `);
  const viewer = useFragment(
    graphql`
      fragment SubmitTagsScreen_viewer on Viewer {
        ...
      }
    `,
    data.viewer,
  );
(property) viewer: {
    readonly " $fragmentRefs": FragmentRefs<"SubmitTagsScreen_viewer">;
}
No overload matches this call.
  The last overload gave the following error.
    Argument of type '{ readonly " $fragmentRefs": FragmentRefs<"SubmitTagsScreen_viewer">; }' is not assignable to parameter of type 'readonly { readonly ' $data'?: unknown; }[]'.
      Type '{ readonly " $fragmentRefs": FragmentRefs<"SubmitTagsScreen_viewer">; }' is missing the following properties from type 'readonly { readonly ' $data'?: unknown; }[]': length, concat, join, slice, and 18 more.ts(2769)
useFragment.d.ts(36, 17): The last overload is declared here.

Adding an annotation to useFragment does fix it

const viewer = useFragment<SubmitTagsScreen_viewer$key>(
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions