Skip to content

Commit

Permalink
fix: accept type parameter for screenProps
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Sep 21, 2019
1 parent 2433071 commit 5c13cea
Showing 1 changed file with 15 additions and 40 deletions.
55 changes: 15 additions & 40 deletions typescript/react-navigation.d.ts
Expand Up @@ -190,16 +190,16 @@ declare module 'react-navigation' {
navigationOptions?: NavigationScreenConfig<Options, NavigationScreenPropType>;
};

export interface NavigationScreenConfigProps<NavigationScreenPropType> {
export interface NavigationScreenConfigProps<NavigationScreenPropType, ScreenProps = unknown> {
navigation: NavigationScreenPropType;
screenProps: unknown;
screenProps: ScreenProps;
theme: SupportedThemes;
}

export type NavigationScreenConfig<Options, NavigationScreenPropType> =
export type NavigationScreenConfig<Options, NavigationScreenPropType, ScreenProps = unknown> =
| Options
| ((
navigationOptionsContainer: NavigationScreenConfigProps<NavigationScreenPropType> & {
navigationOptionsContainer: NavigationScreenConfigProps<NavigationScreenPropType, ScreenProps> & {
navigationOptions: Options;
}
) => Options);
Expand Down Expand Up @@ -542,20 +542,20 @@ declare module 'react-navigation' {
dangerouslyGetParent: () => NavigationScreenProp<S> | undefined;
}

export interface NavigationNavigatorProps<O = {}, S = {}> {
export interface NavigationNavigatorProps<Options = {}, State = {}, ScreenProps = unknown> {
theme?: SupportedThemes | 'no-preference';
detached?: boolean;
navigation?: NavigationProp<S>;
screenProps?: unknown;
navigationOptions?: O;
navigation?: NavigationProp<State>;
screenProps?: ScreenProps;
navigationOptions?: Options;
}

export type NavigatorType =
| 'react-navigation/STACK'
| 'react-navigation/TABS'
| 'react-navigation/DRAWER';

export interface NavigationContainerProps<S = {}, O = {}> {
export interface NavigationContainerProps<State = {}, Options = {}, ScreenProps = unknown> {
uriPrefix?: string | RegExp;
/**
* Controls whether the navigation container handles URLs opened via 'Linking'
Expand All @@ -568,7 +568,7 @@ declare module 'react-navigation' {
nextNavigationState: NavigationState,
action: NavigationAction
) => void | null | undefined;
navigation?: NavigationScreenProp<S>;
navigation?: NavigationScreenProp<State>;
/*
* This prop is no longer supported. Use `loadNavigationState` and
* `persistNavigationState` instead.
Expand All @@ -579,8 +579,8 @@ declare module 'react-navigation' {
persistNavigationState?: (state: NavigationState) => Promise<any>;

renderLoadingExperimental?: React.ComponentType;
screenProps?: unknown;
navigationOptions?: O;
screenProps?: ScreenProps;
navigationOptions?: Options;
style?: StyleProp<ViewStyle>;
}

Expand Down Expand Up @@ -613,9 +613,6 @@ declare module 'react-navigation' {
backBehavior?: 'none' | 'initialRoute';
}

// Return createNavigationContainer
export type _SwitchNavigatorConfig = NavigationSwitchRouterConfig;

export function createSwitchNavigator(
routeConfigMap: NavigationRouteConfigMap<SwitchNavigatorConfig, NavigationScreenProp<NavigationRoute>>,
switchConfig?: SwitchNavigatorConfig
Expand Down Expand Up @@ -738,11 +735,11 @@ declare module 'react-navigation' {
getComponent: () => React.ComponentType;
}

export type NavigationView<O, S> = React.ComponentType<
export type NavigationView<Options, State, ScreenProps = unknown> = React.ComponentType<
{
descriptors: { [key: string]: NavigationDescriptor };
navigationConfig: O;
screenProps?: unknown;
navigationConfig: Options;
screenProps?: ScreenProps;
} & NavigationInjectedProps
>;

Expand Down Expand Up @@ -779,28 +776,6 @@ declare module 'react-navigation' {
Component: NavigationNavigator<Options, NavigationPropType>
): NavigationContainer;

/**
* END MANUAL DEFINITIONS OUTSIDE OF TYPEDEFINITION.JS
*/

/**
* BEGIN CUSTOM CONVENIENCE INTERFACES
*/

export interface NavigationScreenProps<

This comment has been minimized.

Copy link
@mikehardy

mikehardy Sep 22, 2019

Contributor

This was a breaking change for me, and I'm not sure what types to migrate too, there was no guidance in the release notes or breaking change notice

This comment has been minimized.

Copy link
@mikehardy

mikehardy Sep 22, 2019

Contributor

I ended up basically copying this convenience type into my codebase in order to move forward in the patch release stream

This comment has been minimized.

Copy link
@satya164

satya164 Sep 22, 2019

Author Member

@mikehardy it was mentioned in 4.0.0 release notes: https://github.com/react-navigation/react-navigation/releases/tag/v4.0.0

Replace NavigationScreenProps with:

  • NavigationStackScreenProps for createStackNavigator from react-navigation-stack
  • NavigationTabScreenProps for createBottomTabNavigator and createMaterialTopTabNavigator from react-navigation-tabs
  • NavigationDrawerScreenProps for createDrawerNavigator from react-navigation-drawer

This comment has been minimized.

Copy link
@mikehardy

mikehardy Sep 22, 2019

Contributor

they are not compatible, there are non-optional theme and screenProps members on NavigationDrawerScreenProps for instance and I got into a type snarl there 🤔 https://github.com/react-navigation/drawer/blob/master/src/types.tsx#L111

This comment has been minimized.

Copy link
@satya164

satya164 Sep 22, 2019

Author Member

there are non-optional theme and screenProps members

I'm not understanding how you're using this type. Can you show me an example? This is to annotate props of a screen rendered by a navigator. The navigator always passes these props (afaik), so they are not supposed to be optional.

Params = NavigationParams,
Options = {},
NavigationScreenPropType = NavigationScreenProp<NavigationRoute>
> {
navigation: NavigationScreenProp<NavigationRoute<Params>, Params>;
screenProps?: unknown;
navigationOptions?: NavigationScreenConfig<Options, NavigationScreenPropType>;
}

/**
* END CUSTOM CONVENIENCE INTERFACES
*/

export type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;

export type InferProps<
Expand Down

0 comments on commit 5c13cea

Please sign in to comment.