diff --git a/types/react-navigation/index.d.ts b/types/react-navigation/index.d.ts index 241232227e..88d510134d 100644 --- a/types/react-navigation/index.d.ts +++ b/types/react-navigation/index.d.ts @@ -46,10 +46,10 @@ export interface HeaderProps extends NavigationSceneRendererProps { router: NavigationRouter< NavigationState, NavigationStackScreenOptions - >; + >; getScreenDetails: (navigationScene: NavigationScene) => NavigationScreenDetails< NavigationStackScreenOptions - >; + >; style: StyleProp; } @@ -147,9 +147,9 @@ export interface NavigationRouter { export type NavigationScreenOption = T | (( - navigation: NavigationScreenProp, - config: T - ) => T); + navigation: NavigationScreenProp, + config: T +) => T); export interface NavigationScreenDetails { options: T; @@ -169,26 +169,27 @@ export interface NavigationScreenConfigProps { export type NavigationScreenConfig = Options | ((navigationOptionsContainer: NavigationScreenConfigProps & { - navigationOptions: NavigationScreenProp, - }) => Options); + navigationOptions: NavigationScreenProp, +}) => Options); export type NavigationComponent = - NavigationScreenComponent + NavigationScreenComponent | NavigationNavigator; export type NavigationScreenComponent< - Options = {}, - Props = {} -> = React.ComponentType & Props> & -{ navigationOptions?: NavigationScreenConfig }; + Params = NavigationParams, + Options = {}, + Props = {} + > = React.ComponentType & Props> & + { navigationOptions?: NavigationScreenConfig }; export type NavigationNavigator< - State = NavigationState, - Options = {}, - Props = {} -> = React.ComponentType & Props> & { - router: NavigationRouter, - navigationOptions?: NavigationScreenConfig, + State = NavigationState, + Options = {}, + Props = {} + > = React.ComponentType & Props> & { + router: NavigationRouter, + navigationOptions?: NavigationScreenConfig, }; export interface NavigationParams { @@ -332,9 +333,9 @@ export type NavigationRouteConfig = NavigationComponent | ({ } & NavigationScreenRouteConfig); export type NavigationScreenRouteConfig = NavigationComponent | { - screen: NavigationComponent, + screen: NavigationComponent, } | { - getScreen: () => NavigationComponent, + getScreen: () => NavigationComponent, }; export interface NavigationPathsConfig { @@ -351,22 +352,22 @@ export interface NavigationTabRouterConfig { backBehavior?: 'none' | 'initialRoute'; // defaults `initialRoute` } export interface TabScene { - route: NavigationRoute; - focused: boolean; - index: number; - tintColor?: string; + route: NavigationRoute; + focused: boolean; + index: number; + tintColor?: string; } export interface NavigationTabScreenOptions extends NavigationScreenOptions { tabBarIcon?: React.ReactElement | ((options: { tintColor: (string | null), focused: boolean }) => (React.ReactElement< - any + any > | null)); tabBarLabel?: string | React.ReactElement | ((options: { tintColor: (string | null), focused: boolean }) => (React.ReactElement< - any + any > | string | null)); tabBarVisible?: boolean; tabBarTestIDProps?: { testID?: string, accessibilityLabel?: string }; @@ -380,13 +381,13 @@ export interface NavigationDrawerScreenOptions extends NavigationScreenOptions { drawerIcon?: React.ReactElement | ((options: { tintColor: (string | null), focused: boolean }) => (React.ReactElement< - any + any > | null)); drawerLabel?: string | React.ReactElement | ((options: { tintColor: (string | null), focused: boolean }) => (React.ReactElement< - any + any > | null)); } @@ -402,11 +403,11 @@ export interface NavigationProp { } export type EventType = -| 'willFocus' -| 'didFocus' -| 'willBlur' -| 'didBlur' -| 'action'; + | 'willFocus' + | 'didFocus' + | 'willBlur' + | 'didBlur' + | 'action'; export interface NavigationEventPayload { type: EventType; @@ -429,17 +430,17 @@ export interface NavigationScreenProp { goBack: (routeKey?: string | null) => boolean; navigate(options: { routeName: string; - params?: P; + params?: NavigationParams; action?: NavigationAction; key?: string; }): boolean; navigate( routeNameOrOptions: string, - params?: P, + params?: NavigationParams, action?: NavigationAction, ): boolean; getParam: (param: T, fallback?: P[T]) => P[T]; - setParams: (newParams: NavigationParams) => boolean; + setParams: (newParams: P) => boolean; addListener: ( eventName: string, callback: NavigationEventCallback @@ -565,9 +566,9 @@ export interface LayoutEvent { } export type NavigatorType = -| 'react-navigation/STACK' -| 'react-navigation/TABS' -| 'react-navigation/DRAWER'; + | 'react-navigation/STACK' + | 'react-navigation/TABS' + | 'react-navigation/DRAWER'; export function addNavigationHelpers( navigation: { @@ -592,7 +593,7 @@ export interface NavigationContainerProps { export interface NavigationContainer extends React.ComponentClass< NavigationContainerProps & NavigationNavigatorProps -> { + > { router: NavigationRouter; screenProps: { [key: string]: any }; navigationOptions: any; @@ -657,7 +658,7 @@ export function DrawerNavigator( * Tab Navigator */ -// From views/TabView/TabView.js + // From views/TabView/TabView.js export interface TabViewConfig { tabBarComponent?: React.ReactType; tabBarPosition?: 'top' | 'bottom'; @@ -806,7 +807,7 @@ export interface TransitionerState { export class Transitioner extends React.Component< TransitionerProps, TransitionerState -> { } + > { } /** * Tab Router @@ -859,10 +860,10 @@ export function createNavigationContainer( * BEGIN CUSTOM CONVENIENCE INTERFACES */ -export interface NavigationScreenProps { - navigation: NavigationScreenProp>; +export interface NavigationScreenProps { + navigation: NavigationScreenProp, Params>; screenProps?: { [key: string]: any }; - navigationOptions?: NavigationScreenConfig; + navigationOptions?: NavigationScreenConfig; } /** diff --git a/types/react-navigation/react-navigation-tests.tsx b/types/react-navigation/react-navigation-tests.tsx index d70bca3ecd..7e956d2c1a 100644 --- a/types/react-navigation/react-navigation-tests.tsx +++ b/types/react-navigation/react-navigation-tests.tsx @@ -134,7 +134,12 @@ export const AppNavigator = StackNavigator( }, ); -const StatelessScreen: NavigationScreenComponent = () => ; +interface StatelessScreenParams { + testID: string; +} + +const StatelessScreen: NavigationScreenComponent = (props) => + ; StatelessScreen.navigationOptions = { title: 'Stateless' };