v3.5: Wrong TS types for `useLazyQuery`
See original GitHub issueIntended outcome: Successfully upgrade Apollo Client from v3.4 to v3.5.
Actual outcome: TypeScript ESLint warning on this code:
useEffect(() => {
if (!called && inView) {
void runQuery();
}
}, [called, inView, runQuery]);
The !called
check is getting Unnecessary conditional, value is always falsy
. That’s because according to the types, called
is always true
, even for a lazy query. That’s obviously incorrect.
There was no such type mismatch in v3.4.
How to reproduce the issue:
Check called
in any lazy query in a TypeScript codebase. You’ll see it permanently equals true
, according to the types:

I see multiple problems in the existing types:
-
useQuery
shouldn’t returncalled
at all, according to the docs:This field is only present on the result object returned by
useLazyQuery
. -
Per the above note, then, the result object returned when calling the lazy query shouldn’t include
called
, either. -
The result object returned by
useLazyQuery
should includecalled: boolean
.
Versions
System:
OS: Linux 4.19 Debian GNU/Linux 11 (bullseye) 11 (bullseye)
Binaries:
Node: 16.13.0 - /usr/local/bin/node
Yarn: 1.22.17 - /usr/bin/yarn
npm: 8.1.0 - /usr/local/bin/npm
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:6 (5 by maintainers)
FWIW – IIRC (from ages ago! 😅) I was trying to make
QueryResult<...>
the type of non-lazy queries, in which casecalled
would always betrue
because it would be called immediately; only for lazy queries could it be either boolean value.but it sounds like either I didn’t succeed or some type changes in the intervening time lost track of that. either way, sorry for the bug! glad it’s fixed.
Oops, yes, this is definitely a duplicate of #9102.
But I’m going to passive-aggressively leave it to a maintainer to close this, so we can actually get acknowledgment of the issue first 😃