Skip to content
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

Rework ExpoRouter HrefObject #23507

Merged
merged 7 commits into from Jul 15, 2023

Conversation

marklawlor
Copy link
Contributor

@marklawlor marklawlor commented Jul 13, 2023

Why

Reworks how Href and HrefObject works to fix multiple issues with Expo Router types

Fixes:

  • Issues where HrefObject required as const typing under some conditions (Link needs to be "as const" when using typedRoutes router#769)
  • HrefObject now auto-completes all dynamic routes (previously only did static routes)
  • HrefObject params is no longer strict and can accept extra arguments
  • useLocalSearchParams/useSearchParams/useGlobalSearchParams now allow for arbitrary generics
  • If a route is passed as the genertic for useLocalSearchParams/useSearchParams/useGlobalSearchParams will return an object with keys typed for the known parameters, but still allow for arbitrary search params
  • Top level catch all routes (e.g /[...missing]) no longer cause typing to fail
    • e.g <Link href="/(test)/[value]" /> will now correctly error that it should be a HrefObject and not a Href
  • When setting a param it can be a string or number - however it will always be a string when returned from useLocalSearchParams/useSearchParams/useGlobalSearchParams

PR superseeds #23422

Test Plan

Type tests were updated but some things need to be manually tested (like autocomplete)

The project generated by npx create-expo-app@latest --template tabs@49 can be used to easily test.

@expo-bot expo-bot added the bot: passed checks ExpoBot has nothing to complain about label Jul 13, 2023
@marklawlor marklawlor changed the title Marklawlor/cli/typed routes/rework hrefobject Rework ExpoRouter HrefObject Jul 13, 2023
@marklawlor marklawlor marked this pull request as draft July 13, 2023 05:15
@marklawlor marklawlor marked this pull request as ready for review July 13, 2023 06:03
@marklawlor marklawlor merged commit 1106f3a into main Jul 15, 2023
5 checks passed
@marklawlor marklawlor deleted the marklawlor/cli/typed-routes/rework-hrefobject branch July 15, 2023 00:21
byCedric pushed a commit that referenced this pull request Jul 18, 2023
# Why

Reworks how `Href` and `HrefObject` works to fix multiple issues with
Expo Router types

Fixes:
- Issues where HrefObject required `as const` typing under some
conditions (expo/router#769)
- HrefObject now auto-completes all dynamic routes (previously only did
static routes)
- HrefObject `params` is no longer strict and can accept extra arguments
- `useLocalSearchParams`/`useSearchParams`/`useGlobalSearchParams` now
allow for arbitrary generics
- If a route is passed as the genertic for
`useLocalSearchParams`/`useSearchParams`/`useGlobalSearchParams` will
return an object with keys typed for the known parameters, but still
allow for arbitrary search params
- Top level catch all routes (e.g `/[...missing]`) no longer cause
typing to fail
- e.g `<Link href="/(test)/[value]" />` will now correctly error that it
should be a HrefObject and not a Href
- When setting a `param` it can be a `string` or `number` - however it
will always be a string when returned from
`useLocalSearchParams`/`useSearchParams`/`useGlobalSearchParams`

PR superseeds #23422

# Test Plan

Type tests were updated but some things need to be manually tested (like
autocomplete)

The project generated by `npx create-expo-app@latest --template tabs@49`
can be used to easily test.
EvanBacon pushed a commit that referenced this pull request Jul 19, 2023
Reworks how `Href` and `HrefObject` works to fix multiple issues with
Expo Router types

Fixes:
- Issues where HrefObject required `as const` typing under some
conditions (expo/router#769)
- HrefObject now auto-completes all dynamic routes (previously only did
static routes)
- HrefObject `params` is no longer strict and can accept extra arguments
- `useLocalSearchParams`/`useSearchParams`/`useGlobalSearchParams` now
allow for arbitrary generics
- If a route is passed as the genertic for
`useLocalSearchParams`/`useSearchParams`/`useGlobalSearchParams` will
return an object with keys typed for the known parameters, but still
allow for arbitrary search params
- Top level catch all routes (e.g `/[...missing]`) no longer cause
typing to fail
- e.g `<Link href="/(test)/[value]" />` will now correctly error that it
should be a HrefObject and not a Href
- When setting a `param` it can be a `string` or `number` - however it
will always be a string when returned from
`useLocalSearchParams`/`useSearchParams`/`useGlobalSearchParams`

PR superseeds #23422

Type tests were updated but some things need to be manually tested (like
autocomplete)

The project generated by `npx create-expo-app@latest --template tabs@49`
can be used to easily test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: passed checks ExpoBot has nothing to complain about
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants