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

getState typescript error after version 6.1.10 #11893

Open
1 of 12 tasks
bhandanyan-nomad opened this issue Mar 13, 2024 · 2 comments
Open
1 of 12 tasks

getState typescript error after version 6.1.10 #11893

bhandanyan-nomad opened this issue Mar 13, 2024 · 2 comments

Comments

@bhandanyan-nomad
Copy link

bhandanyan-nomad commented Mar 13, 2024

Current behavior

I have an existing function that accepts the navigation object as a prop:

navigation: NavigationProp<ParamListBase, string>,

After upgrading to the latest version of react navigation, this type gives the following typescript error:

Argument of type 'Omit<NavigationProp<RootParamList>, "getState"> & { getState(): Readonly<{ key: string; index: number; routeNames: string[]; history?: unknown[] | undefined; routes: NavigationRoute<...>[]; type: string; stale: false; }> | undefined; }' is not assignable to parameter of type 'NavigationProp<ParamListBase, string>'.
  Type 'Omit<NavigationProp<RootParamList>, "getState"> & { getState(): Readonly<{ key: string; index: number; routeNames: string[]; history?: unknown[] | undefined; routes: NavigationRoute<...>[]; type: string; stale: false; }> | undefined; }' is not assignable to type 'Omit<NavigationHelpersCommon<ParamListBase, Readonly<{ key: string; index: number; routeNames: string[]; history?: unknown[] | undefined; routes: NavigationRoute<ParamListBase, string>[]; type: string; stale: false; }>>, "getParent">'.
    The types returned by 'getState()' are incompatible between these types.
      Type 'Readonly<{ key: string; index: number; routeNames: string[]; history?: unknown[] | undefined; routes: NavigationRoute<ParamListBase, string>[]; type: string; stale: false; }> | undefined' is not assignable to type 'Readonly<{ key: string; index: number; routeNames: string[]; history?: unknown[] | undefined; routes: NavigationRoute<ParamListBase, string>[]; type: string; stale: false; }>'.
        Type 'undefined' is not assignable to type 'Readonly<{ key: string; index: number; routeNames: string[]; history?: unknown[] | undefined; routes: NavigationRoute<ParamListBase, string>[]; type: string; stale: false; }>'.ts(2345)

Expected behavior

I would expect the type here continues to work, or a decent alternative be proposed for how to type a function that accepts the navigation prop.

I can copy the change from inside react navigation in order to work around this issue for now:

navigation: Omit<NavigationProp<ParamListBase, string>, 'getState'> & {
    getState(): NavigationState | undefined;
  },

However, I'm wondering if NavigationProp should be updated accordingly?

Reproduction

https://www.typescriptlang.org/play?#code/PTAEHUFMBsGMHsC2lQBd5oBYoCoE8AHSAZVgCcBLA1UABWgEM8BzM+AVwDsATAGiwoBnUENANQAd0gAjQRVSQAUCEmYKsTKGYUAbpGF4OY0BoadYKdJMoL+gzAzIoz3UNEiPOofEVKVqAHSKymAAmkYI7NCuqGqcANag8ABmIjQUXrFOKBJMggBcISGgoAC0oACCbvCwDKgU8JkY7p7ehCTkVDQS2E6gnPCxGcwmZqDSTgzxxWWVoASMFmgYkAAeRJTInN3ymj4d-jSCeNsMq-wuoPaOltigAKoASgAywhK7SbGQZIIz5VWCFzSeCrZagNYbChbHaxUDcCjJZLfSDbExIAgUdxkUBIursJzCFJtXydaiKKEEeBkGgAb1AADkGDoKMw6g1OLQ2AR+LRHAxEM8hKgAEIMQSQfjscWM5ms+qNUAAXxxbEQoAA5AABSawVClThMllsxrAA31PTqgDcwQQnEENDMAFFVvyFpAAGqOCgMaTuUAAXlAACIABIwaAYcBU6JBxS2wTwdwBCPMAAUTpdiDdnsoPvcAEpgskuLr2Wh9KhUwbZcbOPkGYa5ezOfACAAeXlkfmC+2i8V2VCUTjMAB8+dANMUJRK1aN8s4AWYkFQxFQdUgqfz1sVNsa9v6jdrAdAUsgMrn7M31oU9qrh-nW+CKhwzQ8ZC8iCpzmB7BoXzcZjMOwDBLvwsDQOoiQ+vAegiF4QbOq67iCEGSTYkG4AOKg6rCPSkASEGQQqAA8l8ZDvP2WjLlca7UpArjSHgoBOJ+zLDlg+goAgiDQsIlz-hI0auKIhj4vMjAsGwXDcEEJRAA

Platform

  • Android
  • iOS
  • Web
  • Windows
  • MacOS

Packages

  • @react-navigation/bottom-tabs
  • @react-navigation/drawer
  • @react-navigation/material-top-tabs
  • @react-navigation/stack
  • @react-navigation/native-stack
  • react-native-tab-view

Environment

  • I've removed the packages that I don't use
package version
@react-navigation/native 6.1.16
@react-navigation/bottom-tabs 6.5.19
@react-navigation/drawer 6.6.14
@react-navigation/material-top-tabs 6.6.12
@react-navigation/native-stack 6.9.25
react-native-safe-area-context 4.9.0
react-native-screens 3.29.0
react-native 0.71.16
node 20.11.1
yarn 1.22.19
@bhandanyan-nomad
Copy link
Author

@satya164 what do you think?

@wooller
Copy link

wooller commented Apr 18, 2024

Yeah we seem to be getting this too. Have done the same as @bhandanyan-nomad but definitely doesn't feel like the right thing to be doing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants