react-navigation / react-navigation/react-navigation.github.io

NavigationContainer: initialRouteName: Issue with TypeScript

Open
#1,285 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
324
Forks
2k
PR merge metrics
No merged PRs in 30d

Description

Summary

Following the documentation provided, I see that there is an issue when setting the property initialRouteName to the NavigationContainer tag.

Computer: Mac OS 14.1 (23B74)
Editor: VSCode using React Native Tools by Microsoft.

Description

package.json dependencies:

"dependencies": {
    "@react-navigation/native": "^6.1.9",
    "@react-navigation/native-stack": "^6.9.17",
    "@react-navigation/stack": "^6.3.20",
    "react": "18.2.0",
    "react-native": "0.72.6",
    "react-native-gesture-handler": "^2.13.4",
    "react-native-safe-area-context": "^4.7.4",
    "react-native-screens": "^3.27.0",
  },

App.js:

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 */

import * as React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import Home from './views/Home'

const Stack = createNativeStackNavigator();

function App(): JSX.Element {
  return (
    <NavigationContainer initialRouteName="Home">
      <Stack.Navigator>
        <Stack.Screen name="Home" component={Home} />
      </Stack.Navigator>
    </NavigationContainer>
  );
}

export default App;

VSCode Error Popup:

Type '{ children: Element; initialRouteName: string; }' is not assignable to type 'IntrinsicAttributes & NavigationContainerProps & { theme?: Theme | undefined; linking?: LinkingOptions<RootParamList> | undefined; fallback?: ReactNode; documentTitle?: DocumentTitleOptions | undefined; onReady?: (() => void) | undefined; } & { ...; }'.
  Property 'initialRouteName' does not exist on type 'IntrinsicAttributes & NavigationContainerProps & { theme?: Theme | undefined; linking?: LinkingOptions<RootParamList> | undefined; fallback?: ReactNode; documentTitle?: DocumentTitleOptions | undefined; onReady?: (() => void) | undefined; } & { ...; }'.ts(2322)

Screenshot:

image

Acceptance Criteria

I was expecting no error would show up

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Hello React Navigation documentation page and inspect the example using NavigationContainer and Stack.Navigator. Reproduce the TypeScript error with the shown dependencies, then update the example so the documented route configuration is accepted without the reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
react-native, typescript
Domain
documentation, mobile-dev
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.