Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Wrong Types (or wrong behavior?) with onCompleted #3428

Closed
Titozzz opened this issue Aug 29, 2019 · 2 comments
Closed

Wrong Types (or wrong behavior?) with onCompleted #3428

Titozzz opened this issue Aug 29, 2019 · 2 comments
Assignees

Comments

@Titozzz
Copy link

Titozzz commented Aug 29, 2019

Intended outcome / reproduction:
Types should be trustworthy but:

Using onCompleted(data), typescript says that data cannot be undefined, but onCompleted is called with undefined.

An easy way to reproduce is to do useQuery with cache-only.
Demo:
https://codesandbox.io/s/nifty-northcutt-0ukec

Either onCompleted should not be called when data is not in cache or type should warn that data can be undefined.

Type are specified as follow:

export interface QueryFunctionOptions<TData = any, TVariables = OperationVariables> extends BaseQueryOptions<TVariables> {
    displayName?: string;
    skip?: boolean;
    onCompleted?: (data: TData) => void;
    onError?: (error: ApolloError) => void;
}

Version

System:
OS: macOS 10.14.4
Binaries:
Node: 12.7.0 - ~/.nvm/versions/node/v12.7.0/bin/node
Yarn: 1.17.3 - /usr/local/bin/yarn
npm: 6.10.0 - ~/.nvm/versions/node/v12.7.0/bin/npm
Browsers:
Chrome: 76.0.3809.132
Safari: 12.1
npmPackages:
apollo: 2.17.2 => 2.17.2
@apollo/react-hooks: 3.0.1

@hwillson hwillson self-assigned this Sep 5, 2019
@hwillson
Copy link
Member

hwillson commented Sep 6, 2019

@Titozzz while working on a separate onCompleted issue, I've added a test to verify that onCompleted receives data properly when using cache-only. Everything appears to be working properly (with the latest soon to be published code). Can you take a look a the test in #3461 to see if I'm missing anything that could cause this to happen? I'll close this for now since everything appears to be okay, but let me know otherwise. Thanks!

@hwillson hwillson closed this as completed Sep 6, 2019
@Titozzz
Copy link
Author

Titozzz commented Nov 6, 2019

@hwillson The bug is still here, I've just updated my codesandbox to 3.1.3 and I still can reproduce. Maybe we should reopen this? 😄

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants