Skip to content
Source
Sign inSign up
TanStack/query

TS7030: Not all code paths return a value. #4607

Send to my agent
Closedforgo(GitHub profile, opens in a new tab) opened this issue 4 comments

Describe 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.

Screen Shot 2022-12-07 at 10 50 57 AM

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:

Screen Shot 2022-12-07 at 11 02 12 AM

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

  1. We can set noImplicitReturns: true in our tsconfig:

    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 src directory of react-query? Everything in package.json points towards build:

    https://github.com/TanStack/query/blob/9b21609350d9ad41faf5c2fb0ac6c67e4324a637/packages/react-query/package.json#L13-L23

    and there, we only have .js, .mjs and .d.ts files.

    seems like whatever bundler you're using is set-up in a weird way?

  2. TkDodo added labelspackage: query-core

  3. TkDodo added labelshelp wanted

  4. TkDodo added labelsgood first issue

  5. TkDodo added labelstypes

  6. 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.json though 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.

  7. 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 😅

  8. TkDodo reopened this

  9. @forgo In one of the screenshots i can see an import from @tanstack/query-core/src/types which can be the reason why typescript checks src folder in node_modules Also it should not be necessary. All types are exported via main entry point. Therefore try to eliminate those imports from src folder and error should disappear.

  10. TkDodo closed this

Sign in to join this conversation.