Skip to content

Commit 8774ca9

Browse files
authored
fix: catch missing params when they are required in navigate (facebook#8389)
There is a problem with the enforcement of required params in `navigation.navigate(...)` in TypeScript as described in react-navigation/react-navigation#7936 @Miyou found a fix 🥳. All credits go to him. I needed this so went ahead and submitted a PR and added a test to avoid it from breaking in the future. However note that until this project switches to TypeScript 3.9 with support for [`@ts-expect-error`](https://devblogs.microsoft.com/typescript/announcing-typescript-3-9-beta/#ts-expect-error-comments), it can still break silently. Before the change, this is how the test looks: <img width="861" alt="Screenshot 2020-06-05 at 22 51 00" src="https://user-images.githubusercontent.com/57791/83923057-c53dc180-a781-11ea-8c35-36406a23a717.png"> As you can see it doesn't catch the missing params which are required on line 28. After the change, all expected errors are raised: <img width="812" alt="Screenshot 2020-06-05 at 22 51 59" src="https://user-images.githubusercontent.com/57791/83923413-80665a80-a782-11ea-8ff2-f5af3f4e1f32.png"> Let me know what you think.
1 parent e653d55 commit 8774ca9

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

packages/core/src/types.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ type NavigationHelpersCommon<
152152
* @param [params] Params object for the route.
153153
*/
154154
navigate<RouteName extends keyof ParamList>(
155-
...args: ParamList[RouteName] extends undefined | any
155+
...args: undefined extends ParamList[RouteName]
156156
? [RouteName] | [RouteName, ParamList[RouteName]]
157157
: [RouteName, ParamList[RouteName]]
158158
): void;

0 commit comments

Comments
 (0)