Skip to content

Commit

Permalink
test: add tests for options callback types
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Mar 11, 2024
1 parent 7419e81 commit acba347
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions example/__typechecks__/static.check.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,66 @@ createBottomTabNavigator({
},
});

/**
* Have correct type for screen options callback
*/
createBottomTabNavigator({
screenOptions: ({ route, navigation, theme }) => {
expectTypeOf(route.name).toMatchTypeOf<string>();
expectTypeOf(navigation.getState().type).toMatchTypeOf<'tab'>();
expectTypeOf(navigation.jumpTo).toMatchTypeOf<Function>();
expectTypeOf(theme).toMatchTypeOf<ReactNavigation.Theme>();

return {};
},
screens: {},
});

createBottomTabNavigator({
screens: {
Test: {
screen: () => null,
options: ({ route, navigation, theme }) => {

Check failure on line 212 in example/__typechecks__/static.check.tsx

View workflow job for this annotation

GitHub Actions / build

Type '({ route, navigation, theme }: { route: RouteProp<ParamListBase, "Test">; navigation: BottomTabNavigationProp<ParamListBase, string, string | undefined>; theme: Theme; }) => {}' is not assignable to type 'BottomTabNavigationOptions | ((props: { route: RouteProp<ParamListBase, string>; navigation: BottomTabNavigationProp<ParamListBase, string, string | undefined>; theme: Theme; }) => BottomTabNavigationOptions) | undefined'.

Check failure on line 212 in example/__typechecks__/static.check.tsx

View workflow job for this annotation

GitHub Actions / lint

Type '({ route, navigation, theme }: { route: RouteProp<ParamListBase, "Test">; navigation: BottomTabNavigationProp<ParamListBase, string, string | undefined>; theme: Theme; }) => {}' is not assignable to type 'BottomTabNavigationOptions | ((props: { route: RouteProp<ParamListBase, string>; navigation: BottomTabNavigationProp<ParamListBase, string, string | undefined>; theme: Theme; }) => BottomTabNavigationOptions) | undefined'.
expectTypeOf(route.name).toMatchTypeOf<'Test'>();
expectTypeOf(navigation.getState().type).toMatchTypeOf<'tab'>();
expectTypeOf(navigation.jumpTo).toMatchTypeOf<Function>();
expectTypeOf(theme).toMatchTypeOf<ReactNavigation.Theme>();

return {};
},
},
},
});

/**
* Have correct type for listeners callback
*/
createBottomTabNavigator({
screenListeners: ({ route, navigation }) => {
expectTypeOf(route.name).toMatchTypeOf<string>();
expectTypeOf(navigation.getState().type).toMatchTypeOf<'tab'>();
expectTypeOf(navigation.jumpTo).toMatchTypeOf<Function>();

return {};
},
screens: {},
});

createBottomTabNavigator({
screens: {
Test: {
screen: () => null,
listeners: ({ navigation, route }) => {

Check failure on line 242 in example/__typechecks__/static.check.tsx

View workflow job for this annotation

GitHub Actions / build

Type '({ navigation, route }: { route: RouteProp<ParamListBase, "Test">; navigation: BottomTabNavigationProp<ParamListBase, string, string | undefined>; }) => {}' is not assignable to type 'Partial<{ tabPress: EventListenerCallback<BottomTabNavigationEventMap & EventMapCore<TabNavigationState<ParamListBase>>, "tabPress">; ... 4 more ...; beforeRemove: EventListenerCallback<...>; }> | ((props: { ...; }) => Partial<...>) | undefined'.

Check failure on line 242 in example/__typechecks__/static.check.tsx

View workflow job for this annotation

GitHub Actions / lint

Type '({ navigation, route }: { route: RouteProp<ParamListBase, "Test">; navigation: BottomTabNavigationProp<ParamListBase, string, string | undefined>; }) => {}' is not assignable to type 'Partial<{ tabPress: EventListenerCallback<BottomTabNavigationEventMap & EventMapCore<TabNavigationState<ParamListBase>>, "tabPress">; ... 4 more ...; beforeRemove: EventListenerCallback<...>; }> | ((props: { ...; }) => Partial<...>) | undefined'.
expectTypeOf(route.name).toMatchTypeOf<'Test'>();
expectTypeOf(navigation.getState().type).toMatchTypeOf<'tab'>();
expectTypeOf(navigation.jumpTo).toMatchTypeOf<Function>();

return {};
},
},
},
});

/**
* Requires `screens` to be defined
*/
Expand Down

0 comments on commit acba347

Please sign in to comment.