[TS] createNavigationContainerRef create an incompatible ref type

2
closed
retyui
retyui
Posted 1 month ago

[TS] createNavigationContainerRef create an incompatible ref type #10049

Current behavior

export const navigationRef = createNavigationContainerRef()

<NavigationContainer
      ref={navigationRef}
      ^^^
      TS2322: Type 'NavigationContainerRefWithCurrent<RootParamList>' is not assignable to type 'Ref<NavigationContainerRef<{}>>'. 

      Type 'NavigationContainerRefWithCurrent<RootParamList>' is not assignable to type 'RefObject<NavigationContainerRef<{}>>'. 
        Types of property 'current' are incompatible. 
          Type 'NavigationContainerRef<RootParamList>' is not assignable to type 'NavigationContainerRef<{}>'. 
            Type 'NavigationContainerRef<RootParamList>' is not assignable to type 'PrivateValueStore<{}, never, {}>'. 
              The types of '''.b' are incompatible between these types. 
              Type 'string' is not assignable to type 'never'. 

>

To fix it need to pass an empty ParamList

-createNavigationContainerRef()
+createNavigationContainerRef<{}>()

Expected behavior

No TS errors

Reproduction

...

Platform

  • Android
  • iOS
  • Web
  • Windows
  • MacOS

Packages

Environment

package version
@react-navigation/native ~6.0.1
@react-navigation/bottom-tabs ^6.0.5
@react-navigation/drawer
@react-navigation/material-bottom-tabs
@react-navigation/material-top-tabs
@react-navigation/stack ~6.0.1
@react-navigation/native-stack ^6.0.2
react-native-safe-area-context
react-native-screens
react-native-gesture-handler
react-native-reanimated
react-native-tab-view
react-native-pager-view
react-native
expo
node
npm or yarn
github-actions[bot]
github-actions[bot]
Created 1 month ago

Hey! Thanks for opening the issue. The issue doesn't seem to contain a link to a repro (a snack.expo.dev link or link to a GitHub repo under your username).

Can you provide a minimal repro which demonstrates the issue? A repro will help us debug the issue faster. Please try to keep the repro as small as possible and make sure that we can run it without additional setup.

github-actions[bot]
github-actions[bot]
Created 1 month ago

Couldn't find version numbers for the following packages in the issue:

  • @react-navigation/drawer
  • @react-navigation/material-bottom-tabs
  • @react-navigation/material-top-tabs

Can you update the issue to include version numbers for those packages? The version numbers must match the format 1.2.3.

The versions mentioned in the issue for the following packages differ from the latest versions on npm:

  • @react-navigation/native (found: 6.0.1, latest: 6.0.6)
  • @react-navigation/bottom-tabs (found: 6.0.5, latest: 6.0.9)
  • @react-navigation/stack (found: 6.0.1, latest: 6.0.11)

Can you verify that the issue still exists after upgrading to the latest versions of these packages?