-
Notifications
You must be signed in to change notification settings - Fork 786
Typescript: ChildProps.data should not be optional #1083
Comments
I'd like to add to this one that instead of data being optional, it is the results that should be optional, in the export interface OptionProps<TProps, TResult> {
ownProps: TProps;
data: QueryProps & Partial<TResult>;
mutate?: MutationFunc<TResult>;
} Are you willing to accept a PR for this? Is there any caveat with this proposed change? |
What you call |
Yeah, duh, good call! haha will update |
Did look up here https://www.typescriptlang.org/docs/handbook/advanced-types.html. Actually both |
Looks as this was merged and included in version 1.4.16 but export type ChildProps<P, R> = P & {
data?: QueryProps & Partial<R>;
mutate?: MutationFunc<R>;
}; Edit: Saw #1143 (comment) now. Looks like this is the reason |
Yeah, I think the reason it was set back to optional is that since the HOC is used for both queries and mutations, and since currently there's no way to tell Typescript how the HOC will act like, the type definitions need to allow both to be optional, since for queries you'll get |
This issue has been automatically labled because it has not had recent activity. If you have not received a response from anyone, please mention the repository maintainer (most likely @jbaxleyiii). It will be closed if no further activity occurs. Thank you for your contributions to React Apollo! |
@leoasis Maybe would be good to create another type for props with queries only Eg. Also this official example doesn't work now because of optional typings https://www.apollographql.com/docs/react/features/static-typing.html#classes-vs-functions |
@jurosh yeah the problem with that is that by design the |
This issue has been automatically labled because it has not had recent activity. If you have not received a response from anyone, please mention the repository maintainer (most likely @jbaxleyiii). It will be closed if no further activity occurs. Thank you for your contributions to React Apollo! |
#1369 offers a refined test case that should be considered, though it is a duplicate of this issue. Actually, perhaps since it is succinctly stated perhaps we should close this one and keep that one open? |
Intended outcome:
The typescript definition of
ChildProps.data
should be non-optional, since according to the documentation (http://dev.apollodata.com/react/api-queries.html#graphql-query-data) thedata
property has aloading
/error
subproperty to check for completion/errors.Actual outcome:
The actual type definition is
forcing users to always check if
data
is defined before being able to accessdata.loading
or other properties.One example from the documentation
would fail if using typescript because of
data?
.Version
The text was updated successfully, but these errors were encountered: