relay-compiler-language-typescript
relay-compiler-language-typescript copied to clipboard
Emitted types are invalid?
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:
TodoList.tsx@line:16TodoScreen.tsx@line:30
what are the errors? can you provide them here?
@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; } & { ...; }'
@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; } & { ...; }'
@karlmarxlopez have you found a solution to this issue? I'm currently using typescripts as keywords which doesn't feel good.
@filame I think I ended up typecasting it. Something like this, someFragmentData as MyFragment_foo$key
@filame I think I ended up typecasting it. Something like this,
someFragmentData as MyFragment_foo$key
Ok, same for me. Thanks for your reply!