-
Notifications
You must be signed in to change notification settings - Fork 787
improve QueryResult data
typescript typing
#1917
Comments
This is definitely the wrong type for this; it just bit me. Given the server-side types:
This typing causes the following line to pass, even though it contains a major type error (note: I'm using apollo-codegen to generate TS types for this component's query):
Note that I think the line @jzimmek mentioned should be Update: Ah, I see the difficulty. TypeScript doesn't recognize Here's a possible solution that doesn't break the public API for JS users (unless you happen to be querying a field called
|
I too have been struggling with the very permissive types; I would love to see something union-based. For what it's worth, one thing that's stopped me has been the fact that, between |
data
typescript typing
We are going to stick to |
Hi @danilobuerger , I am not sure to fully understand why you want to stick to Furthermore, it seems wrong, no ? We have type error at runtime, because we check if data is defined, and then if ok, we use Are we the only one in this case ? |
Its not wrong. If you get anything other than |
ok we have Thank you for your help ! |
@eltonio450 you can follow apollographql/apollo-client#4356 |
yes, done, thank you :) |
The current QueryResult typing defines
react-apollo/src/Query.tsx
Lines 89 to 97 in a4c8703
I am not super deep into the react apollo codebase, but I this can eventually be solved by using "Discriminated Unions" in typescript: http://www.typescriptlang.org/docs/handbook/advanced-types.html
The "discriminant" attribute (eg. "resultType") would have two possible values: "data" | "error"
(Eventually even a third one: "data-and-error" if this is a valid state in apollo)
Anyone already investigated this as a possible solution?
The text was updated successfully, but these errors were encountered: