Skip to content

Commit

Permalink
feat: make ScreenProps parametrizable in TypeScript (#6496)
Browse files Browse the repository at this point in the history
This change allows for the following to be written:

```tsx
const TreatmentPlanDrawerItem = createStackNavigator(
  {
    Screen: {
      screen: Screen,
     // t is of type i18next.TFunction via the type casting below.
      navigationOptions: ({ screenProps }) => ({
        title: screenProps.t('title'),
      })
    },
  } as NavigationRouteConfigMap<
    NavigationStackOptions,
    NavigationStackProp<NavigationRoute, any>,
    { t: i18next.TFunction }
  >
);
```
  • Loading branch information
wcandillon authored and satya164 committed Jan 23, 2020
1 parent ccb1f61 commit ef83e73
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions typescript/react-navigation.d.ts
Expand Up @@ -482,7 +482,7 @@ declare module 'react-navigation' {
| NavigationSwitchAction
| { type: 'CHILD_ACTION'; key?: string };

export type NavigationRouteConfig<Options, NavigationScreenPropType> =
export type NavigationRouteConfig<Options, NavigationScreenPropType, ScreenProps = unknown> =
| NavigationComponent<Options, NavigationScreenPropType>
| (
| { screen: NavigationComponent<Options, NavigationScreenPropType> }
Expand All @@ -494,7 +494,8 @@ declare module 'react-navigation' {
}) & {
navigationOptions?: NavigationScreenConfig<
Options,
NavigationScreenPropType
NavigationScreenPropType,
ScreenProps
>;
params?: { [key: string]: any };
path?: string;
Expand All @@ -514,10 +515,11 @@ declare module 'react-navigation' {
resetOnBlur?: boolean;
}

export interface NavigationRouteConfigMap<Options, NavigationScreenPropType> {
export interface NavigationRouteConfigMap<Options, NavigationScreenPropType, ScreenProps = unknown> {
[routeName: string]: NavigationRouteConfig<
Options,
NavigationScreenPropType
NavigationScreenPropType,
ScreenProps
>;
}

Expand Down

0 comments on commit ef83e73

Please sign in to comment.