@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/lib/commonjs/types.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/typescript/commonjs/src/types.d.ts +21 -14
- package/lib/typescript/commonjs/src/types.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/useDescriptors.d.ts +18 -18
- package/lib/typescript/commonjs/src/useNavigationBuilder.d.ts +28 -28
- package/lib/typescript/commonjs/src/useNavigationBuilder.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/useNavigationCache.d.ts +9 -9
- package/lib/typescript/commonjs/src/useNavigationHelpers.d.ts +9 -9
- package/lib/typescript/commonjs/tsconfig.build.tsbuildinfo +1 -1
- package/lib/typescript/module/src/types.d.ts +21 -14
- package/lib/typescript/module/src/types.d.ts.map +1 -1
- package/lib/typescript/module/src/useDescriptors.d.ts +18 -18
- package/lib/typescript/module/src/useNavigationBuilder.d.ts +28 -28
- package/lib/typescript/module/src/useNavigationBuilder.d.ts.map +1 -1
- package/lib/typescript/module/src/useNavigationCache.d.ts +9 -9
- package/lib/typescript/module/src/useNavigationHelpers.d.ts +9 -9
- package/lib/typescript/module/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/types.tsx +33 -46
- package/src/useNavigationBuilder.tsx +1 -1
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:
|
|
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:
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
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:
|
|
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:
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
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
|
|
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
|
>(
|