diff --git a/src/Hooks.ts b/src/Hooks.ts index 0cdae3b..04c5a4e 100644 --- a/src/Hooks.ts +++ b/src/Hooks.ts @@ -17,13 +17,21 @@ import { EventType, } from 'react-navigation'; -export function useNavigation(): NavigationScreenProp { - const navigation = useContext(NavigationContext) as any; // TODO typing? +type NavigationType = S & NavigationScreenProp; + +type NavigationWithParamType = NavigationType & NavigationScreenProp; + +export function useNavigation(): NavigationType; + +export function useNavigation(): NavigationWithParamType; + +export function useNavigation() { + const navigation = useContext(NavigationContext); if (!navigation) { throw new Error( "react-navigation hooks require a navigation context but it couldn't be found. " + - "Make sure you didn't forget to create and render the react-navigation app container. " + - 'If you need to access an optional navigation object, you can useContext(NavigationContext), which may return' + "Make sure you didn't forget to create and render the react-navigation app container. " + + 'If you need to access an optional navigation object, you can useContext(NavigationContext), which may return' ); } return navigation;