[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
This commit is contained in:
Gregory Benner 2018-10-19 09:57:34 -07:00 committed by Brent Vatne
parent 0c9014e52f
commit 0c4845f2ff
2 changed files with 12 additions and 1 deletions

View File

@ -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

View File

@ -533,7 +533,16 @@ declare module 'react-navigation' {
eventName: string,
callback: NavigationEventCallback
) => NavigationEventSubscription,
getParam: (paramName: string, fallback?: any) => any,
getParam: <ParamName>(
paramName: ParamName,
fallback?: $ElementType<$PropertyType<{|
...{| params: {| [ParamName]: void |} |},
...$Exact<S>,
|}, 'params'>, ParamName>,
) => $ElementType<$PropertyType<{|
...{| params: {| [ParamName]: void |} |},
...$Exact<S>,
|}, 'params'>, ParamName>,
dangerouslyGetParent: () => NavigationScreenProp<*>,
isFocused: () => boolean,
// Shared action creators that exist for all routers