mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-06 12:36:49 +08:00
Merge pull request #27904 from LinusU/react-navigation-fallback
[react-navigation] Fix return type when fallback provided
This commit is contained in:
4
types/react-navigation/index.d.ts
vendored
4
types/react-navigation/index.d.ts
vendored
@@ -18,6 +18,7 @@
|
||||
// Jérémy Magrin <https://github.com/magrinj>
|
||||
// Luca Campana <https://github.com/TizioFittizio>
|
||||
// Ullrich Schaefer <https://github.com/stigi>
|
||||
// Linus Unnebäck <https://github.com/LinusU>
|
||||
// Yosuke Seki <https://github.com/jshosomichi>
|
||||
// Jake <https://github.com/jakebooyah>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
@@ -588,7 +589,8 @@ export interface NavigationScreenProp<S, P = NavigationParams> {
|
||||
openDrawer: () => any;
|
||||
closeDrawer: () => any;
|
||||
toggleDrawer: () => any;
|
||||
getParam: <T extends keyof P>(param: T, fallback?: P[T]) => P[T];
|
||||
getParam<T extends keyof P>(param: T, fallback: NonNullable<P[T]>): NonNullable<P[T]>;
|
||||
getParam<T extends keyof P>(param: T): P[T];
|
||||
setParams: (newParams: Partial<P>) => boolean;
|
||||
addListener: (
|
||||
eventName: 'willBlur' | 'willFocus' | 'didFocus' | 'didBlur',
|
||||
|
||||
@@ -497,6 +497,7 @@ const CustomHeaderStack = createStackNavigator({
|
||||
|
||||
interface ScreenProps {
|
||||
name: string;
|
||||
optionalAge?: number;
|
||||
onPlay(): void;
|
||||
}
|
||||
|
||||
@@ -513,9 +514,16 @@ class SetParamsTest extends React.Component<NavigationScreenProps<ScreenProps>>
|
||||
|
||||
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 (
|
||||
<Text>My name is {name}</Text>
|
||||
<Text>My name is {name} and I am {age} years old.</Text>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user