TS7030: Not all code paths return a value. #4607
Send to my agentDescribe the bug#
ERROR in /Users/elliott/IdeaProjects/rino/node_modules/@tanstack/query-core/src/utils.ts
417:38-65
[tsl] ERROR in /Users/elliott/IdeaProjects/rino/node_modules/@tanstack/query-core/src/utils.ts(417,39)
TS7030: Not all code paths return a value.
ERROR in /Users/elliott/IdeaProjects/rino/node_modules/@tanstack/query-core/src/focusManager.ts
16:17-31
[tsl] ERROR in /Users/elliott/IdeaProjects/rino/node_modules/@tanstack/query-core/src/focusManager.ts(16,18)
TS7030: Not all code paths return a value.
ERROR in /Users/elliott/IdeaProjects/rino/node_modules/@tanstack/query-core/src/onlineManager.ts
16:17-32
[tsl] ERROR in /Users/elliott/IdeaProjects/rino/node_modules/@tanstack/query-core/src/onlineManager.ts(16,18)
TS7030: Not all code paths return a value.
ERROR in /Users/elliott/IdeaProjects/rino/node_modules/@tanstack/query-core/src/infiniteQueryBehavior.ts
187:3-22
[tsl] ERROR in /Users/elliott/IdeaProjects/rino/node_modules/@tanstack/query-core/src/infiniteQueryBehavior.ts(187,4)
TS7030: Not all code paths return a value.
ERROR in /Users/elliott/IdeaProjects/rino/node_modules/@tanstack/query-core/src/infiniteQueryBehavior.ts
205:3-22
[tsl] ERROR in /Users/elliott/IdeaProjects/rino/node_modules/@tanstack/query-core/src/infiniteQueryBehavior.ts(205,4)
TS7030: Not all code paths return a value.
ERROR in /Users/elliott/IdeaProjects/rino/node_modules/@tanstack/query-core/src/retryer.ts
184:16-23
[tsl] ERROR in /Users/elliott/IdeaProjects/rino/node_modules/@tanstack/query-core/src/retryer.ts(184,17)
TS7030: Not all code paths return a value.
This is obviously coming from the lines mentioned in the errors where functions are implicitly returning.
Normally I didn't think TypeScript would error on things from node_modules when I set skipLibCheck: true in my tsconfig.json; however, the TypeScript documentation on "skipLibCheck" specifically mentions it is only applicable to .d.ts files and not just plain .ts files.
The obvious fix here is to have an explicit return undefined outside of the if statement in the first example. Presumably the fix would be similar for the other errors above.
I wasn't seeing this error the other day when installing react-query 4.18.0, and I noticed I was on 4.19.1 now, but even after reverting the version, I can't seem to get rid of this error and my app fails to compile entirely.
Does anybody have a clue what's happening here or a way to get around it? I think it would be best to just address these implicit returns in the library long-term, but obviously I might be missing something here to prevent this minor issue from allowing me to run an entire application.
Your minimal, reproducible example#
https://codesandbox.io/s/strange-hill-ydm9dr?file=/tsconfig.json
Steps to reproduce#
I'm sorry the codesandbox above doesn't recreate the error, but it seems strange that the errors in my application are only inside the source code for query-core and none of my application -- even after setting my skipLibCheck: true in my tsconfig.json -- There definitely seems to be some implicit returns that can be fixed in the libarary -- though I'm not sure why they're cropping up for me suddenly.
I've tried nuking my node_modules and running yarn cache clean, reinstalling, etc, but these errors started showing up and won't go away, and I could use your help.
yarn add @tanstack/react-query
...do some things with useQuery in application. For example:
yarn start
Expected behavior#
I expect to be able to install and import react-query source and types without critical errors under the /node_modules/@tanstack/query-core/src directory.
How often does this bug happen?#
Every time
Screenshots or Videos#
No response
Platform#
macOS Monterey: Version 12.3.1 Chrome: Version 108.0.5359.94 (Official Build) (x86_64)
Tanstack Query version#
4.19.1 and 4.18.0
TypeScript version#
4.8.2
Additional context#
No response
TkDodo added labelspackage: query-core
TkDodo added labelshelp wanted
TkDodo added labelsgood first issue
TkDodo added labelstypes
seems like whatever bundler you're using is set-up in a weird way?
That's definitely possible, but thank you for the follow up, we will do the same temporary fix on our
tsconfig.jsonthough I would prefer to not need that setting just to align with 3rd party code conventions -- as you mention it could possibly be some weirdness in our webpack config/plugins. Hard to say at the moment.Thank you for your help.
forgo(GitHub profile, opens in a new tab) closed this
I would still like to keep this issue open because changing the tsconfig on our end is something we can do.
But it should be independent of your issue. You TS compiler should not look at src code of 3rd party libs 😅
TkDodo reopened this
@forgo In one of the screenshots i can see an import from
@tanstack/query-core/src/typeswhich can be the reason why typescript checkssrcfolder innode_modulesAlso it should not be necessary. All types are exported via main entry point. Therefore try to eliminate those imports fromsrcfolder and error should disappear.TkDodo closed this
Sign in to join this conversation.
We can set
noImplicitReturns: truein ourtsconfig:https://github.com/TanStack/query/blob/741cc3f2e0e876af52846211d01989947007fc10/tsconfig.base.json#L10
and fix the issues that arise. I see it yields 6 errors. Would you like to contribute that?
However, I'm not sure why your app would pick up the
srcdirectory of react-query? Everything in package.json points towardsbuild:https://github.com/TanStack/query/blob/9b21609350d9ad41faf5c2fb0ac6c67e4324a637/packages/react-query/package.json#L13-L23
and there, we only have
.js,.mjsand.d.tsfiles.seems like whatever bundler you're using is set-up in a weird way?