diff --git a/types/react-navigation/index.d.ts b/types/react-navigation/index.d.ts index 26d1a10d0f..31c3269af4 100644 --- a/types/react-navigation/index.d.ts +++ b/types/react-navigation/index.d.ts @@ -18,6 +18,7 @@ // Jérémy Magrin // Luca Campana // Ullrich Schaefer +// Linus Unnebäck // Yosuke Seki // Jake // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -588,7 +589,8 @@ export interface NavigationScreenProp { openDrawer: () => any; closeDrawer: () => any; toggleDrawer: () => any; - getParam: (param: T, fallback?: P[T]) => P[T]; + getParam(param: T, fallback: NonNullable): NonNullable; + getParam(param: T): P[T]; setParams: (newParams: Partial

) => boolean; addListener: ( eventName: 'willBlur' | 'willFocus' | 'didFocus' | 'didBlur', diff --git a/types/react-navigation/react-navigation-tests.tsx b/types/react-navigation/react-navigation-tests.tsx index 3cde3d892c..60ca9b4758 100644 --- a/types/react-navigation/react-navigation-tests.tsx +++ b/types/react-navigation/react-navigation-tests.tsx @@ -497,6 +497,7 @@ const CustomHeaderStack = createStackNavigator({ interface ScreenProps { name: string; + optionalAge?: number; onPlay(): void; } @@ -513,9 +514,16 @@ class SetParamsTest extends React.Component> render() { const name = this.props.navigation.getParam('name'); + const age = this.props.navigation.getParam('optionalAge'); + + // $ExpectType number | undefined + this.props.navigation.getParam('optionalAge'); + + // $ExpectType number + this.props.navigation.getParam('optionalAge', 0); return ( - My name is {name} + My name is {name} and I am {age} years old. ); } }