Skip to content

Commit 3f341f2

Browse files
fix: nested route should combine all params (#3)
1 parent 7ba7c6f commit 3f341f2

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ const manager = new Manager({
100100
user: {
101101
url: '/user',
102102
params: {
103-
// required
103+
// required string
104104
id: '',
105105
// required union
106106
id: '' as 'aaa' | 'dddd',
107107
// required enum
108108
id: DD,
109-
// optional
109+
// optional string
110110
id: undefined,
111111
// optional union
112112
id: undefined as 'aaa' | 'dddd' | undefined,

src/interfaces.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,23 @@ type TRouteParamsType<TObj extends Record<string, any>> = TNonEmptyParams<{
6363
: IsEnum<TObj[field]>;
6464
}>;
6565

66+
// @ts-ignore
67+
type MergeObjects<T, TU> = { [K in keyof T | keyof TU]: K extends keyof T ? T[K] : TU[K] };
68+
6669
type TRouteParamsValues<
6770
TConfig extends TRouterConfig,
6871
TKey extends TRouteKeys<TConfig>,
6972
> = TKey extends `${infer TPrefix}.${infer TPostfix}`
7073
? TPostfix extends string
7174
? TConfig[TPrefix]['children'] extends TRouterConfig
72-
? // @ts-ignore
73-
TRouteParamsValues<TConfig[TPrefix]['children'], TPostfix>
75+
? MergeObjects<
76+
// @ts-ignore
77+
TRouteParamsValues<TConfig[TPrefix]['children'], TPostfix>,
78+
TConfig[TPrefix]['params']
79+
>
7480
: never
7581
: never
76-
: TConfig[TKey]['params'] extends Record<string, any>
77-
? TConfig[TKey]['params']
78-
: never;
82+
: MergeObjects<TConfig[TKey]['params'], object>;
7983

8084
type TRouteKeys<TConfig extends TRouterConfig> = keyof {
8185
[P in keyof TConfig as P extends string ? TRouteKeysDeep<TConfig, P> : never]: any;

0 commit comments

Comments
 (0)