Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript: Query is required in default query options #3583

Closed
josh18 opened this issue Jun 13, 2018 · 3 comments
Closed

Typescript: Query is required in default query options #3583

josh18 opened this issue Jun 13, 2018 · 3 comments

Comments

@josh18
Copy link

josh18 commented Jun 13, 2018

Intended outcome:
Typescript doesn't complain when setting default query options without a query value

defaultOptions: {
    query: {
        fetchPolicy: 'no-cache'
    }
}

Actual outcome:
Property 'query' is missing in type '{ fetchPolicy: "no-cache"; }'.

Argument of type '{ link: ApolloLink; cache: InMemoryCache; defaultOptions: { query: { fetchPolicy: "no-cache"; }; ...' is not assignable to parameter of type 'ApolloClientOptions<NormalizedCacheObject>'. Types of property 'defaultOptions' are incompatible. Type '{ query: { fetchPolicy: "no-cache"; }; }' is not assignable to type 'DefaultOptions'. Types of property 'query' are incompatible. Type '{ fetchPolicy: "no-cache"; }' is not assignable to type 'QueryOptions<OperationVariables>'. Property 'query' is missing in type '{ fetchPolicy: "no-cache"; }'.

Versions
Apollo client 2.3.3 (was working in 2.3.1, haven't tested 2.3.2)

Notes
I am assuming this was an unintended change from #3569?

@hwillson
Copy link
Member

Definitely not intentional @josh18 - thanks for letting us know! I'll have a fix deployed shortly.

hwillson added a commit that referenced this issue Jun 14, 2018
When the new `QueryBaseOptions` and `QueryOptions` interfaces
were created in
eb89b23,
`ModifiableWatchQueryOptions` was replaced by `QueryOptions`
when checking the `query` `defaultOptions` used in the
Apollo Client constructor. Unfortunately, this introduced a
small type check bug since the `query` property in `QueryOptions`
is a mandatory property, whereas `ModifiableWatchQueryOptions`
did not include this property. This commit replaces the use of
`QueryOptions` with `QueryBaseOptions` when type checking
`query` in `defaultOptions`, since `QueryBaseOptions` doesn't
have a `query` property.

Fixes #3583.
@hwillson
Copy link
Member

apollo-client 2.3.4 was just released, and includes a fix for this. Thanks!

@josh18
Copy link
Author

josh18 commented Jun 14, 2018

So fast! Thanks for your help 🙂

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants