Typescript does not consider that the data returned by the useQuery hook can be undefined
Describe the bug
Here is an example of what I mean, data for Typescript is always a RoomProductI[] type, that is, the type that the function returns, without processing what might return undefined
Also pay attention to the auxiliary text under the variable definition in the vscode popup window
Your minimal, reproducible example
I'm lazy, I can't create it now
Steps to reproduce
Dependencies:
{
"dependencies": {
"@baronha/ting": "1.2.2",
"@gorhom/bottom-sheet": "4.6.4",
"@hookform/resolvers": "3.9.0",
"@react-native-async-storage/async-storage": "2.0.0",
"@react-native-clipboard/clipboard": "1.14.1",
"@react-native-community/geolocation": "3.3.0",
"@react-native-community/netinfo": "11.3.2",
"@react-native-masked-view/masked-view": "0.3.1",
"@react-native-menu/menu": "1.1.2",
"@react-navigation/bottom-tabs": "6.6.1",
"@react-navigation/native": "6.1.18",
"@react-navigation/native-stack": "6.11.0",
"@reduxjs/toolkit": "2.2.7",
"@shopify/react-native-skia": "1.3.11",
"@tanstack/react-query": "5.53.3",
"axios": "1.7.5",
"date-fns": "3.6.0",
"events": "3.3.0",
"expo": "51.0.31",
"expo-av": "14.0.7",
"expo-linking": "^6.3.1",
"expo-screen-orientation": "7.0.5",
"expo-splash-screen": "0.27.5",
"expo-status-bar": "~1.12.1",
"immer": "10.1.1",
"markdown-it-block-embed": "0.0.3",
"react": "18.3.1",
"react-hook-form": "7.53.0",
"react-native": "0.75.2",
"react-native-config": "1.5.3",
"react-native-device-info": "11.1.0",
"react-native-fs": "2.20.0",
"react-native-gesture-handler": "2.18.1",
"react-native-haptic-feedback": "2.3.1",
"react-native-image-crop-picker": "0.41.2",
"react-native-keychain": "8.2.0",
"react-native-linear-gradient": "2.8.3",
"react-native-maps": "1.18.0",
"react-native-markdown-display": "7.0.2",
"react-native-permissions": "4.1.5",
"react-native-qrcode-svg": "6.3.2",
"react-native-reanimated": "3.15.0",
"react-native-safe-area-context": "4.10.9",
"react-native-screens": "3.34.0",
"react-native-share": "10.2.1",
"react-native-svg": "15.6.0",
"react-native-svg-transformer": "1.5.0",
"react-native-vision-camera": "4.5.2",
"react-native-webview": "13.12.0",
"react-native-yamap": "4.6.1",
"react-redux": "9.1.2",
"redux-persist": "6.0.0",
"rn-fetch-blob": "0.12.0",
"yup": "1.4.0"
},
"devDependencies": {
"@babel/core": "7.25.2",
"@tanstack/eslint-plugin-query": "5.53.0",
"@types/events": "3.0.3",
"@types/react": "18.3.4",
"@typescript-eslint/eslint-plugin": "8.3.0",
"@typescript-eslint/parser": "8.3.0",
"babel-plugin-module-resolver": "5.0.2",
"eslint": "^8.0.0",
"eslint-config-expo": "7.1.2",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react": "^7.35.0",
"eslint-plugin-react-hooks": "4.6.2",
"eslint-plugin-react-native": "4.1.0",
"prettier": "^3.3.3",
"react-native-dotenv": "3.4.11",
"reactotron-react-native": "^5.1.8",
"typescript": "5.3.3"
},
}
I have already tried to install the latest version of typescript and the one that stands in expo by default
TS config file:
{
"extends": "expo/tsconfig.base",
"compilerOptions": {
"baseUrl": ".",
"paths": {
"ui/*": ["src/components/ui/*"],
"context/*": ["src/context/*"],
"hooks/*": ["src/hooks/*"],
"store/*": ["src/store/*"],
"stacks/*": ["src/stacks/*"],
"screens/*": ["src/screens/*"],
"components/*": ["src/components/*"],
"assets/*": ["assets/*"],
"src/*": ["src/*"]
},
"lib": ["ES2021"],
"skipLibCheck": true
}
}
I have already tried to remove the lines from tsconfig.json and restart but the result is the same
Expected behavior
Setup react native expo project and download latest version of tanstack/react-query
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
This is npx expo-env-info output
expo-env-info 1.2.0 environment info: System: OS: macOS 14.6.1 Shell: 5.9 - /bin/zsh Binaries: Node: 22.2.0 - /opt/homebrew/bin/node Yarn: 1.22.22 - /opt/homebrew/bin/yarn npm: 10.7.0 - /opt/homebrew/bin/npm Watchman: 2024.05.06.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.15.2 - /opt/homebrew/bin/pod SDKs: iOS SDK: Platforms: DriverKit 23.5, iOS 17.5, macOS 14.5, tvOS 17.5, visionOS 1.2, watchOS 10.5 IDEs: Android Studio: 2023.3 AI-233.14808.21.2331.11842104 Xcode: 15.4/15F31d - /usr/bin/xcodebuild npmPackages: expo: 51.0.31 => 51.0.31 react: 18.3.1 => 18.3.1 react-native: 0.75.2 => 0.75.2 npmGlobalPackages: eas-cli: 10.2.4 Expo Workflow: bare
Tanstack Query adapter
react-query
TanStack Query version
5.53.3, also try downgrade, same issue was appeared
TypeScript version
5.3.3/5.5.4
Additional context
Interesting...
I'm lazy, too.
Haha, okay man