From 0c4845f2ffd425a6194a06996241c037f65870fc Mon Sep 17 00:00:00 2001 From: Gregory Benner Date: Fri, 19 Oct 2018 09:57:34 -0700 Subject: [PATCH] [flow] typecheck getParam to actually check that key and fallback are valid (#5074) * Update flow type definition for getParam to actually check key and fallback are valid * add changelog entry for `getParam` flow type changes * Return "any" in `getParam` if params are not defined in the navigation state * use void in place of any --- CHANGELOG.md | 2 ++ flow/react-navigation.js | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1be14f7..4d6f523 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +- Update `getParam` flow typings to check `key` and `fallback` arguments, as well as return the correct type automatically. + ## [2.17.0] - [2018-09-25](https://github.com/react-navigation/react-navigation/releases/tag/2.17.0) ### Changed diff --git a/flow/react-navigation.js b/flow/react-navigation.js index b3d5c3b..193ce7e 100644 --- a/flow/react-navigation.js +++ b/flow/react-navigation.js @@ -533,7 +533,16 @@ declare module 'react-navigation' { eventName: string, callback: NavigationEventCallback ) => NavigationEventSubscription, - getParam: (paramName: string, fallback?: any) => any, + getParam: ( + paramName: ParamName, + fallback?: $ElementType<$PropertyType<{| + ...{| params: {| [ParamName]: void |} |}, + ...$Exact, + |}, 'params'>, ParamName>, + ) => $ElementType<$PropertyType<{| + ...{| params: {| [ParamName]: void |} |}, + ...$Exact, + |}, 'params'>, ParamName>, dangerouslyGetParent: () => NavigationScreenProp<*>, isFocused: () => boolean, // Shared action creators that exist for all routers