Skip to content

Commit

Permalink
Fix a bug when undefined query params could be passed
Browse files Browse the repository at this point in the history
  • Loading branch information
mchudy committed Sep 16, 2020
1 parent 73eb6f3 commit 8a221e9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions __tests__/types/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const routes = createRouting({
// Passes without arguments when there are no required parameters or query parameters
expectType<string>(routes.login());

// Does not allow undefined query params in single paths
expectError(routes.login({}, { a: "a" }));

// Passes when the required param is specified
expectType<string>(routes.user({ userId: "12" }));

Expand Down
4 changes: 3 additions & 1 deletion src/createRouting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ type PathPatternArgs<
> = [TRequiredParams] extends [never]
? [TRequiredQuery] extends [never]
? [TOptionalParams] extends [never]
? [EmptyObject?, Partial<Record<TOptionalQuery, string>>?]
? [TOptionalQuery] extends [never]
? []
: [EmptyObject?, Partial<Record<TOptionalQuery, string>>?]
: [Partial<Record<TOptionalParams, string>>?]
: [TOptionalParams] extends [never]
? [EmptyObject, Record<TRequiredQuery, string> & Partial<Record<TOptionalQuery, string>>]
Expand Down

0 comments on commit 8a221e9

Please sign in to comment.