relay-compiler-language-typescript icon indicating copy to clipboard operation
relay-compiler-language-typescript copied to clipboard

Emitted types are invalid?

Open SpaghettiC0des opened this issue 5 years ago • 6 comments

Sorry for my ignorance, I just started using Relay and friends. I chose it over other existing GraphQL client because IMHO, it is worth it in the long run.

I am following the todo list tutorial on Relay's docs and converting the HTML into React Native. There's no error on the runtime but there are static type errors, especially on the generated types for fragments.

Here's a reproduction of the issue, you don't need to run it just open it on VScode.

Open the following files:

  1. TodoList.tsx@line:16
  2. TodoScreen.tsx@line:30

SpaghettiC0des avatar Oct 16 '20 14:10 SpaghettiC0des

what are the errors? can you provide them here?

sibelius avatar Oct 16 '20 14:10 sibelius

@sibelius

Type '{ readonly " $fragmentRefs": FragmentRefs<"TodoList_user">; } | null' is not assignable to type '_FragmentRefs<"TodoList_user">'.
  Type 'null' is not assignable to type '_FragmentRefs<"TodoList_user">'.ts(2322)
TodoList.tsx(8, 3): The expected type comes from property 'user' which is declared here on type 'IntrinsicAttributes & MappedFragmentProps<Pick<Props, "user">> & { componentRef?: ((ref: any) => void) | undefined; } & { ...; }'

SpaghettiC0des avatar Oct 16 '20 14:10 SpaghettiC0des

@sibelius Similar issue when I use the experimental hooks. On the same repro branch above, please check out hooks branch, then open TodoScreen line 25.

<TodoApp /> contains a nested fragment, but it seems like it does not emit the proper type on the root component/query?

Type '{ readonly " $fragmentRefs": FragmentRefs<"TodoApp_viewer">; } | null' is not assignable to type '_FragmentRefs<"TodoApp_viewer">'.
  Type 'null' is not assignable to type '_FragmentRefs<"TodoApp_viewer">'.ts(2322)
TodoApp.tsx(13, 3): The expected type comes from property 'viewer' which is declared here on type 'IntrinsicAttributes & MappedFragmentProps<Pick<Props, "viewer">> & { componentRef?: ((ref: any) => void) | undefined; } & { ...; }'

SpaghettiC0des avatar Oct 17 '20 16:10 SpaghettiC0des

@karlmarxlopez have you found a solution to this issue? I'm currently using typescripts as keywords which doesn't feel good.

filame avatar May 17 '21 07:05 filame

@filame I think I ended up typecasting it. Something like this, someFragmentData as MyFragment_foo$key

SpaghettiC0des avatar May 22 '21 17:05 SpaghettiC0des

@filame I think I ended up typecasting it. Something like this, someFragmentData as MyFragment_foo$key

Ok, same for me. Thanks for your reply!

filame avatar May 25 '21 05:05 filame