-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useLocalSearchParams should not use Partial for params #28813
Comments
This is a limitation of TypeScript. TypeScript is not "file" aware, it doesn't know (or care) where the types are being used. The best "fix" to this I've seen is SveltKit, but that adds a layer of complexity I'm not sure that we want (e.g importing from a "magical" path instead of the module) I'm going to close this as at this current time, we're not going to fix this - but that may change in the future |
Sorry, I dont get it. Why not just remove |
I upgraded expo-router, and now I have tons of files to "fix". I don't understand why you used |
I agree with @rodrigorm and @elfennani, it's not clear to me why the |
Running into this issue, and I think it's worth a second look. expo/packages/expo-router/src/hooks.ts Lines 102 to 104 in 32c14ee
Since it's a generic, it should be up to the developer to decide whether a property is optional, and not make the entire object
The |
`useLocalSearchParams` accepts a generic that's defined by the user, so it should let user decide what's optional and not make the entire return type `Partial`. In fact, according to the official [docs](https://docs.expo.dev/router/reference/search-parameters/#route-parameters-versus-search-parameters) > When the app/[user] route is matched, the user parameter is passed to the component and never a nullish value. The use of `Partial` contradicts the statement above. Issue expo#28813
Minimal reproducible example
Does not have yet
Which package manager are you using? (Yarn is recommended)
yarn
If the issue is web-related, please select the bundler (
web.bundler
in theapp.json
)None
Summary
When using
useLocalSearchParams
, I am expecting to type the params according to its usage. For an route file likeapp/[teamId]/(root)/(pickups)/pickups/[id]/index.tsx
, whe using the hook in typescript like below, I should expectteamId
andid
to be required and not optional as it is required in the route path, but the usage ofPartial
at [https://github.com/expo/expo/blob/main/packages/expo-router/src/hooks.ts#L102] forces me to use the non-null assertion!
on every variable usage inside the page.Environment
expo-env-info 1.2.0 environment info:
System:
OS: Linux 5.15 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish)
Shell: 5.1.16 - /bin/bash
Binaries:
Node: 18.17.1 - /usr/bin/node
Yarn: 1.22.19 - /usr/bin/yarn
npm: 9.6.7 - /usr/bin/npm
npmPackages:
expo: ~51.0.4 => 51.0.4
expo-router: ~3.5.12 => 3.5.12
react: 18.2.0 => 18.2.0
react-dom: 18.2.0 => 18.2.0
react-native: 0.74.1 => 0.74.1
react-native-web: ~0.19.11 => 0.19.11
npmGlobalPackages:
eas-cli: 9.0.5
Expo Workflow: managed
The text was updated successfully, but these errors were encountered: