Skip to content

Commit

Permalink
react-navigation libdef: Make *NavigationProp covariant in RouteName …
Browse files Browse the repository at this point in the history
…param.

When we make our own types based on `StackNavigationProp` -- e.g.,
when we define `AppNavigationProp`, in an upcoming commit -- we'll
want those types to be covariant in their own `RouteName` param.

That's because we want, e.g., `AppNavigationProp<'realm'>` to be
recognized as a subtype of
`AppNavigationProp<'realm' | 'account' | …>`, i.e.,
`AppNavigationProp<$Keys<AppNavigatorParamList>>`.

So, start by making `NavigationProp`, `StackNavigationProp`, and
`InexactStackNavigationProp` covariant in their `RouteName` params,
following discussion at
zulip#4393 (comment).

Also make the change for types of navigators other than stack
navigators, across all the libdef files. There's a lot of repetition
because libdef files can't import types from other files [1].

[1] zulip#3458 (comment)
  • Loading branch information
chrisbobbe committed Jan 13, 2021
1 parent 8d91769 commit ff50f04
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 60 deletions.
24 changes: 12 additions & 12 deletions flow-typed/@react-navigation/bottom-tabs_v5.x.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ declare module '@react-navigation/bottom-tabs' {

declare export type NavigationProp<
ParamList: ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
State: PossiblyStaleNavigationState = PossiblyStaleNavigationState,
ScreenOptions: { ... } = { ... },
EventMap: EventMapBase = EventMapCore<State>,
Expand Down Expand Up @@ -1135,7 +1135,7 @@ declare module '@react-navigation/bottom-tabs' {

declare type InexactStackNavigationProp<
ParamList: ParamListBase = ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
Options: { ... } = StackOptions,
EventMap: EventMapBase = StackNavigationEventMap,
> = {
Expand All @@ -1149,7 +1149,7 @@ declare module '@react-navigation/bottom-tabs' {

declare export type StackNavigationProp<
ParamList: ParamListBase = ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
Options: { ... } = StackOptions,
EventMap: EventMapBase = StackNavigationEventMap,
> = $Exact<InexactStackNavigationProp<ParamList, RouteName, Options, EventMap>>;
Expand Down Expand Up @@ -1215,7 +1215,7 @@ declare module '@react-navigation/bottom-tabs' {

declare type InexactTabNavigationProp<
ParamList: ParamListBase,
RouteName: $Keys<ParamList>,
+RouteName: $Keys<ParamList>,
Options: { ... },
EventMap: EventMapBase,
> = {
Expand All @@ -1226,14 +1226,14 @@ declare module '@react-navigation/bottom-tabs' {

declare export type InexactBottomTabNavigationProp<
ParamList: ParamListBase = ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
Options: { ... } = BottomTabOptions,
EventMap: EventMapBase = BottomTabNavigationEventMap,
> = InexactTabNavigationProp<ParamList, RouteName, Options, EventMap>;

declare export type BottomTabNavigationProp<
ParamList: ParamListBase = ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
Options: { ... } = BottomTabOptions,
EventMap: EventMapBase = BottomTabNavigationEventMap,
> = $Exact<InexactBottomTabNavigationProp<ParamList, RouteName, Options, EventMap>>;
Expand Down Expand Up @@ -1317,14 +1317,14 @@ declare module '@react-navigation/bottom-tabs' {

declare export type InexactMaterialBottomTabNavigationProp<
ParamList: ParamListBase = ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
Options: { ... } = MaterialBottomTabOptions,
EventMap: EventMapBase = MaterialBottomTabNavigationEventMap,
> = InexactTabNavigationProp<ParamList, RouteName, Options, EventMap>;

declare export type MaterialBottomTabNavigationProp<
ParamList: ParamListBase = ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
Options: { ... } = MaterialBottomTabOptions,
EventMap: EventMapBase = MaterialBottomTabNavigationEventMap,
> = $Exact<InexactMaterialBottomTabNavigationProp<ParamList, RouteName, Options, EventMap>>;
Expand Down Expand Up @@ -1451,14 +1451,14 @@ declare module '@react-navigation/bottom-tabs' {

declare export type InexactMaterialTopTabNavigationProp<
ParamList: ParamListBase = ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
Options: { ... } = MaterialTopTabOptions,
EventMap: EventMapBase = MaterialTopTabNavigationEventMap,
> = InexactTabNavigationProp<ParamList, RouteName, Options, EventMap>;

declare export type MaterialTopTabNavigationProp<
ParamList: ParamListBase = ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
Options: { ... } = MaterialTopTabOptions,
EventMap: EventMapBase = MaterialTopTabNavigationEventMap,
> = $Exact<InexactMaterialTopTabNavigationProp<ParamList, RouteName, Options, EventMap>>;
Expand Down Expand Up @@ -1609,7 +1609,7 @@ declare module '@react-navigation/bottom-tabs' {

declare export type InexactDrawerNavigationProp<
ParamList: ParamListBase = ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
Options: { ... } = DrawerOptions,
EventMap: EventMapBase = DrawerNavigationEventMap,
> = {
Expand All @@ -1623,7 +1623,7 @@ declare module '@react-navigation/bottom-tabs' {

declare export type DrawerNavigationProp<
ParamList: ParamListBase = ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
Options: { ... } = DrawerOptions,
EventMap: EventMapBase = DrawerNavigationEventMap,
> = $Exact<InexactDrawerNavigationProp<ParamList, RouteName, Options, EventMap>>;
Expand Down
24 changes: 12 additions & 12 deletions flow-typed/@react-navigation/drawer_v5.x.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ declare module '@react-navigation/drawer' {

declare export type NavigationProp<
ParamList: ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
State: PossiblyStaleNavigationState = PossiblyStaleNavigationState,
ScreenOptions: { ... } = { ... },
EventMap: EventMapBase = EventMapCore<State>,
Expand Down Expand Up @@ -1135,7 +1135,7 @@ declare module '@react-navigation/drawer' {

declare type InexactStackNavigationProp<
ParamList: ParamListBase = ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
Options: { ... } = StackOptions,
EventMap: EventMapBase = StackNavigationEventMap,
> = {
Expand All @@ -1149,7 +1149,7 @@ declare module '@react-navigation/drawer' {

declare export type StackNavigationProp<
ParamList: ParamListBase = ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
Options: { ... } = StackOptions,
EventMap: EventMapBase = StackNavigationEventMap,
> = $Exact<InexactStackNavigationProp<ParamList, RouteName, Options, EventMap>>;
Expand Down Expand Up @@ -1215,7 +1215,7 @@ declare module '@react-navigation/drawer' {

declare type InexactTabNavigationProp<
ParamList: ParamListBase,
RouteName: $Keys<ParamList>,
+RouteName: $Keys<ParamList>,
Options: { ... },
EventMap: EventMapBase,
> = {
Expand All @@ -1226,14 +1226,14 @@ declare module '@react-navigation/drawer' {

declare export type InexactBottomTabNavigationProp<
ParamList: ParamListBase = ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
Options: { ... } = BottomTabOptions,
EventMap: EventMapBase = BottomTabNavigationEventMap,
> = InexactTabNavigationProp<ParamList, RouteName, Options, EventMap>;

declare export type BottomTabNavigationProp<
ParamList: ParamListBase = ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
Options: { ... } = BottomTabOptions,
EventMap: EventMapBase = BottomTabNavigationEventMap,
> = $Exact<InexactBottomTabNavigationProp<ParamList, RouteName, Options, EventMap>>;
Expand Down Expand Up @@ -1317,14 +1317,14 @@ declare module '@react-navigation/drawer' {

declare export type InexactMaterialBottomTabNavigationProp<
ParamList: ParamListBase = ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
Options: { ... } = MaterialBottomTabOptions,
EventMap: EventMapBase = MaterialBottomTabNavigationEventMap,
> = InexactTabNavigationProp<ParamList, RouteName, Options, EventMap>;

declare export type MaterialBottomTabNavigationProp<
ParamList: ParamListBase = ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
Options: { ... } = MaterialBottomTabOptions,
EventMap: EventMapBase = MaterialBottomTabNavigationEventMap,
> = $Exact<InexactMaterialBottomTabNavigationProp<ParamList, RouteName, Options, EventMap>>;
Expand Down Expand Up @@ -1451,14 +1451,14 @@ declare module '@react-navigation/drawer' {

declare export type InexactMaterialTopTabNavigationProp<
ParamList: ParamListBase = ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
Options: { ... } = MaterialTopTabOptions,
EventMap: EventMapBase = MaterialTopTabNavigationEventMap,
> = InexactTabNavigationProp<ParamList, RouteName, Options, EventMap>;

declare export type MaterialTopTabNavigationProp<
ParamList: ParamListBase = ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
Options: { ... } = MaterialTopTabOptions,
EventMap: EventMapBase = MaterialTopTabNavigationEventMap,
> = $Exact<InexactMaterialTopTabNavigationProp<ParamList, RouteName, Options, EventMap>>;
Expand Down Expand Up @@ -1609,7 +1609,7 @@ declare module '@react-navigation/drawer' {

declare export type InexactDrawerNavigationProp<
ParamList: ParamListBase = ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
Options: { ... } = DrawerOptions,
EventMap: EventMapBase = DrawerNavigationEventMap,
> = {
Expand All @@ -1623,7 +1623,7 @@ declare module '@react-navigation/drawer' {

declare export type DrawerNavigationProp<
ParamList: ParamListBase = ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
Options: { ... } = DrawerOptions,
EventMap: EventMapBase = DrawerNavigationEventMap,
> = $Exact<InexactDrawerNavigationProp<ParamList, RouteName, Options, EventMap>>;
Expand Down
24 changes: 12 additions & 12 deletions flow-typed/@react-navigation/material-top-tabs_v5.x.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ declare module '@react-navigation/material-top-tabs' {

declare export type NavigationProp<
ParamList: ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
State: PossiblyStaleNavigationState = PossiblyStaleNavigationState,
ScreenOptions: { ... } = { ... },
EventMap: EventMapBase = EventMapCore<State>,
Expand Down Expand Up @@ -1135,7 +1135,7 @@ declare module '@react-navigation/material-top-tabs' {

declare type InexactStackNavigationProp<
ParamList: ParamListBase = ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
Options: { ... } = StackOptions,
EventMap: EventMapBase = StackNavigationEventMap,
> = {
Expand All @@ -1149,7 +1149,7 @@ declare module '@react-navigation/material-top-tabs' {

declare export type StackNavigationProp<
ParamList: ParamListBase = ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
Options: { ... } = StackOptions,
EventMap: EventMapBase = StackNavigationEventMap,
> = $Exact<InexactStackNavigationProp<ParamList, RouteName, Options, EventMap>>;
Expand Down Expand Up @@ -1215,7 +1215,7 @@ declare module '@react-navigation/material-top-tabs' {

declare type InexactTabNavigationProp<
ParamList: ParamListBase,
RouteName: $Keys<ParamList>,
+RouteName: $Keys<ParamList>,
Options: { ... },
EventMap: EventMapBase,
> = {
Expand All @@ -1226,14 +1226,14 @@ declare module '@react-navigation/material-top-tabs' {

declare export type InexactBottomTabNavigationProp<
ParamList: ParamListBase = ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
Options: { ... } = BottomTabOptions,
EventMap: EventMapBase = BottomTabNavigationEventMap,
> = InexactTabNavigationProp<ParamList, RouteName, Options, EventMap>;

declare export type BottomTabNavigationProp<
ParamList: ParamListBase = ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
Options: { ... } = BottomTabOptions,
EventMap: EventMapBase = BottomTabNavigationEventMap,
> = $Exact<InexactBottomTabNavigationProp<ParamList, RouteName, Options, EventMap>>;
Expand Down Expand Up @@ -1317,14 +1317,14 @@ declare module '@react-navigation/material-top-tabs' {

declare export type InexactMaterialBottomTabNavigationProp<
ParamList: ParamListBase = ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
Options: { ... } = MaterialBottomTabOptions,
EventMap: EventMapBase = MaterialBottomTabNavigationEventMap,
> = InexactTabNavigationProp<ParamList, RouteName, Options, EventMap>;

declare export type MaterialBottomTabNavigationProp<
ParamList: ParamListBase = ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
Options: { ... } = MaterialBottomTabOptions,
EventMap: EventMapBase = MaterialBottomTabNavigationEventMap,
> = $Exact<InexactMaterialBottomTabNavigationProp<ParamList, RouteName, Options, EventMap>>;
Expand Down Expand Up @@ -1451,14 +1451,14 @@ declare module '@react-navigation/material-top-tabs' {

declare export type InexactMaterialTopTabNavigationProp<
ParamList: ParamListBase = ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
Options: { ... } = MaterialTopTabOptions,
EventMap: EventMapBase = MaterialTopTabNavigationEventMap,
> = InexactTabNavigationProp<ParamList, RouteName, Options, EventMap>;

declare export type MaterialTopTabNavigationProp<
ParamList: ParamListBase = ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
Options: { ... } = MaterialTopTabOptions,
EventMap: EventMapBase = MaterialTopTabNavigationEventMap,
> = $Exact<InexactMaterialTopTabNavigationProp<ParamList, RouteName, Options, EventMap>>;
Expand Down Expand Up @@ -1609,7 +1609,7 @@ declare module '@react-navigation/material-top-tabs' {

declare export type InexactDrawerNavigationProp<
ParamList: ParamListBase = ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
Options: { ... } = DrawerOptions,
EventMap: EventMapBase = DrawerNavigationEventMap,
> = {
Expand All @@ -1623,7 +1623,7 @@ declare module '@react-navigation/material-top-tabs' {

declare export type DrawerNavigationProp<
ParamList: ParamListBase = ParamListBase,
RouteName: $Keys<ParamList> = $Keys<ParamList>,
+RouteName: $Keys<ParamList> = $Keys<ParamList>,
Options: { ... } = DrawerOptions,
EventMap: EventMapBase = DrawerNavigationEventMap,
> = $Exact<InexactDrawerNavigationProp<ParamList, RouteName, Options, EventMap>>;
Expand Down
Loading

0 comments on commit ff50f04

Please sign in to comment.