Definitelytyped: @types/react-navigation has no exported member 'createAppContainer'.

Created on 14 Dec 2018  路  7Comments  路  Source: DefinitelyTyped/DefinitelyTyped

  • [x] I tried using the @types/react-navigation package and had problems.
  • [x] I tried using the latest stable version of tsc. https://www.npmjs.com/package/typescript
  • [x] I have a question that is inappropriate for StackOverflow. (Please ask any appropriate questions there).
  • [x] [Mention](https://github.com/blog/821-mention-somebody-they-re-notified) the authors (see Definitions by: in index.d.ts) so they can respond.

    • Authors: @huhuanming @mhcgrq @fangpenlin @petejkim @iRoachie @phanalpha @charlesfamu @timwangdev @bang88 @svbutko @levito @YourGamesBeOver @ArmandoAssuncao @cliedeman @magrinj @TizioFittizio @stigi @LinusU @jshosomichi @jakebooyah @brunoro @DenisFrezzato @mickaelw @alechill @builtbyproxy @jkillian @jeroenvervaeke @chagasaway

Looks like we need some typings for v3 of react-navigation.

package.json:

"@types/react-navigation": "^2.13.8",
"react-navigation": "^3.0.8"

App.tsx

import { createStackNavigator, createAppContainer  } from 'react-navigation';

Error:

{
    "resource": "....../src/App.tsx",
    "owner": "typescript",
    "code": "2305",
    "severity": 8,
    "message": "Module '\"....../node_modules/@types/react-navigation\"' has no exported member 'createAppContainer'.",
    "source": "ts",
    "startLineNumber": 13,
    "startColumn": 32,
    "endLineNumber": 13,
    "endColumn": 50
}

Most helpful comment

@sm1th looks like this one could be closed as @types/[email protected] has been released and types for discussed methods and properties now exist:

https://www.npmjs.com/package/@types/react-navigation

All 7 comments

same with defaultNavigationOptions. really looks like somehow types were downgraded to 2.x version

"@types/react-navigation": "^2.13.8",
"react-navigation": "^3.0.8",

Error:

Object literal may only specify known properties, and 'defaultNavigationOptions' does not exist in type 'BottomTabNavigatorConfig'
Argument of type '{ initialRouteName: string; defaultNavigationOptions: ({ navigation }: any) => { animationEnabled: boolean; tabBarColor: string; tabBarOptions: { showLabel: boolean; style: { backgroundColor: string; borderTopWidth: number; borderTopColor: string; }; activeTintColor: string; inactiveTintColor: string; }; tabBarIcon:...' is not assignable to parameter of type 'BottomTabNavigatorConfig'.
  Object literal may only specify known properties, and 'defaultNavigationOptions' does not exist in type 'BottomTabNavigatorConfig'.

Code:

import { createBottomTabNavigator } from 'react-navigation'

/* ... */

const Tabs =  createBottomTabNavigator({
  /* screens definition */
}, {
  initialRouteName: INITIAL_ROUTE,
  defaultNavigationOptions: ({ navigation }) => {
    /* ... */
  }
})

Is there any temporary solution around this?

@sorakthunly I switched to using react-navigation 2.x.x for now.

Having the same problems.

For someone else who still wants to keep the benefit of the typings while still using [email protected], I recommend trying this.

const reactNavigation = require('react-navigation');
const createAppContainer = reactNavigation.createAppContainer;

createAppContainer will not have a type definition but at least it's a temporary workgroup. With this you can also create your own type definition by doing:

export interface AppContainer {
  ..
}
const appContainer: AppContainer = createAppContainer(...);

@sm1th looks like this one could be closed as @types/[email protected] has been released and types for discussed methods and properties now exist:

https://www.npmjs.com/package/@types/react-navigation

@nicholasrq Super!

Was this page helpful?
0 / 5 - 0 ratings