@react-navigation/core 7.0.0-rc.12 → 7.0.0-rc.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/types.tsx CHANGED
@@ -22,6 +22,21 @@ declare global {
22
22
 
23
23
  type Keyof<T extends {}> = Extract<keyof T, string>;
24
24
 
25
+ type ScreenParamsPair<
26
+ ParamList extends ParamListBase,
27
+ RouteName extends keyof ParamList,
28
+ > = {
29
+ // First we use a mapped type to get an union of screen & params pairs
30
+ // Then we pick the pair which matches the RouteName
31
+ // Mapped type is used instead of just ParamList[RouteName]
32
+ // Otherwise it'll result in union of all params leading to incorrect types
33
+ [Screen in keyof ParamList]: undefined extends ParamList[Screen] // Params are either undefined or a union with undefined
34
+ ?
35
+ | [screen: Screen] // if the params are optional, we don't have to provide it
36
+ | [screen: Screen, params: ParamList[Screen]]
37
+ : [screen: Screen, params: ParamList[Screen]];
38
+ }[RouteName];
39
+
25
40
  export type DefaultNavigatorOptions<
26
41
  ParamList extends ParamListBase,
27
42
  NavigatorID extends string | undefined,
@@ -239,18 +254,7 @@ type NavigationHelpersCommon<
239
254
  * @param [params] Params object for the route.
240
255
  */
241
256
  navigate<RouteName extends keyof ParamList>(
242
- ...args: // This condition allows us to iterate over a union type
243
- // This is to avoid getting a union of all the params from `ParamList[RouteName]`,
244
- // which will get our types all mixed up if a union RouteName is passed in.
245
- RouteName extends unknown
246
- ? // This condition checks if the params are optional,
247
- // which means it's either undefined or a union with undefined
248
- undefined extends ParamList[RouteName]
249
- ?
250
- | [screen: RouteName] // if the params are optional, we don't have to provide it
251
- | [screen: RouteName, params: ParamList[RouteName]]
252
- : [screen: RouteName, params: ParamList[RouteName]]
253
- : never
257
+ ...args: ScreenParamsPair<ParamList, RouteName>
254
258
  ): void;
255
259
 
256
260
  /**
@@ -259,14 +263,14 @@ type NavigationHelpersCommon<
259
263
  * @param route Object with `name` for the route to navigate to, and a `params` object.
260
264
  */
261
265
  navigate<RouteName extends keyof ParamList>(
262
- options: RouteName extends unknown
263
- ? {
264
- name: RouteName;
265
- params: ParamList[RouteName];
266
- path?: string;
267
- merge?: boolean;
268
- }
269
- : never
266
+ options: {
267
+ [Screen in keyof ParamList]: {
268
+ name: Screen;
269
+ params: ParamList[Screen];
270
+ path?: string;
271
+ merge?: boolean;
272
+ };
273
+ }[RouteName]
270
274
  ): void;
271
275
 
272
276
  /**
@@ -278,18 +282,7 @@ type NavigationHelpersCommon<
278
282
  * @param [params] Params object for the route.
279
283
  */
280
284
  navigateDeprecated<RouteName extends keyof ParamList>(
281
- ...args: // This condition allows us to iterate over a union type
282
- // This is to avoid getting a union of all the params from `ParamList[RouteName]`,
283
- // which will get our types all mixed up if a union RouteName is passed in.
284
- RouteName extends unknown
285
- ? // This condition checks if the params are optional,
286
- // which means it's either undefined or a union with undefined
287
- undefined extends ParamList[RouteName]
288
- ?
289
- | [screen: RouteName] // if the params are optional, we don't have to provide it
290
- | [screen: RouteName, params: ParamList[RouteName]]
291
- : [screen: RouteName, params: ParamList[RouteName]]
292
- : never
285
+ ...args: ScreenParamsPair<ParamList, RouteName>
293
286
  ): void;
294
287
 
295
288
  /**
@@ -300,13 +293,13 @@ type NavigationHelpersCommon<
300
293
  * @param route Object with `name` for the route to navigate to, and a `params` object.
301
294
  */
302
295
  navigateDeprecated<RouteName extends keyof ParamList>(
303
- options: RouteName extends unknown
304
- ? {
305
- name: RouteName;
306
- params: ParamList[RouteName];
307
- merge?: boolean;
308
- }
309
- : never
296
+ options: {
297
+ [Screen in keyof ParamList]: {
298
+ name: Screen;
299
+ params: ParamList[Screen];
300
+ merge?: boolean;
301
+ };
302
+ }[RouteName]
310
303
  ): void;
311
304
 
312
305
  /**
@@ -316,13 +309,7 @@ type NavigationHelpersCommon<
316
309
  * @param [params] Params object for the route.
317
310
  */
318
311
  preload<RouteName extends keyof ParamList>(
319
- ...args: RouteName extends unknown
320
- ? undefined extends ParamList[RouteName]
321
- ?
322
- | [screen: RouteName]
323
- | [screen: RouteName, params: ParamList[RouteName]]
324
- : [screen: RouteName, params: ParamList[RouteName]]
325
- : never
312
+ ...args: ScreenParamsPair<ParamList, RouteName>
326
313
  ): void;
327
314
 
328
315
  /**
@@ -249,7 +249,7 @@ const getRouteConfigsFromChildren = <
249
249
  export function useNavigationBuilder<
250
250
  State extends NavigationState,
251
251
  RouterOptions extends DefaultRouterOptions,
252
- ActionHelpers extends Record<string, () => void>,
252
+ ActionHelpers extends Record<string, (...args: any) => void>,
253
253
  ScreenOptions extends {},
254
254
  EventMap extends Record<string, any>,
255
255
  >(