Skip to content

Commit 49c7eef

Browse files
committed
@react-navigation/stack libdef: Simplify setParams a bit.
As it says in the comment, Flow has some trouble with the more complex type in types-first mode. It would give some wrong-looking errors: Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ flow-typed/@react-navigation/stack_v5.x.x.js:844:22 object type [1] is incompatible with undefined [2] in the first argument. [incompatible-type] flow-typed/@react-navigation/stack_v5.x.x.js [2] 420│ declare type $IsUndefined<X> = $IsA<X, void>; : 841│ +setOptions: (options: $Shape<ScreenOptions>) => void, 842│ +setParams: ( 843│ params: $If< 844│ $IsUndefined<$ElementType<ParamList, RouteName>>, 845│ empty, 846│ $Shape<$NonMaybeType<$ElementType<ParamList, RouteName>>>, 847│ >, src/nav/AppNavigator.js [1] 53│ chat: RouteParamsOf<typeof ChatScreen>, Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ src/chat/ChatScreen.js:113:57 Cannot call navigation.setParams with object literal bound to params because object literal [1] is incompatible with empty [2]. [incompatible-call] src/chat/ChatScreen.js 110│ 111│ const { narrow, editMessage } = route.params; 112│ const setEditMessage = useCallback( [1] 113│ (value: EditMessage | null) => navigation.setParams({ editMessage: value }), 114│ [navigation], 115│ ); 116│ flow-typed/@react-navigation/stack_v5.x.x.js [2] 843│ params: $If< 844│ $IsUndefined<$ElementType<ParamList, RouteName>>, 845│ empty, 846│ $Shape<$NonMaybeType<$ElementType<ParamList, RouteName>>>, 847│ >,
1 parent 6992939 commit 49c7eef

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

flow-typed/@react-navigation/stack_v5.x.x.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -840,11 +840,15 @@ declare module '@react-navigation/stack' {
840840
>>,
841841
+setOptions: (options: $Shape<ScreenOptions>) => void,
842842
+setParams: (
843-
params: $If<
844-
$IsUndefined<$ElementType<ParamList, RouteName>>,
845-
empty,
846-
$Shape<$NonMaybeType<$ElementType<ParamList, RouteName>>>,
847-
>,
843+
// We've edited this to be less complicated, so Flow in types-first
844+
// mode can handle it.
845+
//
846+
// A slight downside of the edit is that the more complicated thing
847+
// used to error when you tried to use `setParams` on a screen whose
848+
// type says it has no params. Now we don't get those errors.
849+
// Hopefully that kind of error is easy enough to avoid without help
850+
// from the type-checker though.
851+
params: $Shape<$NonMaybeType<$ElementType<ParamList, RouteName>>>,
848852
) => void,
849853
...
850854
};

0 commit comments

Comments
 (0)