Skip to content

Commit

Permalink
fix: improve type of route()
Browse files Browse the repository at this point in the history
Improves return type of route() by reducing Omit<...> and intersection types.

fix #3
  • Loading branch information
uhyo committed Oct 17, 2020
1 parent 7778f9a commit cae6bb6
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/builder/PathRouteBuilder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,34 @@ export class PathRouteBuilder<
callback?: (route: PathSingleRouteInterface<ActionResult, Match>) => void
): PathRouteBuilder<
ActionResult,
Omit<Defs, Key> &
{
[K in Key]: RouteDefinition<ActionResult, Match>;
},
Key extends keyof Defs
? {
[K in keyof Defs]: Key extends K
? RouteDefinition<ActionResult, Match>
: Defs[K];
}
: {
[K in keyof Defs | Key]: K extends keyof Defs
? Defs[K]
: RouteDefinition<ActionResult, Match>;
},
AnyFlag,
ExactFlag,
Match
> {
const result = new PathRouteBuilder<
ActionResult,
Omit<Defs, Key> &
{
[K in Key]: RouteDefinition<ActionResult, Match>;
},
Key extends keyof Defs
? {
[K in keyof Defs]: Key extends K
? RouteDefinition<ActionResult, Match>
: Defs[K];
}
: {
[K in keyof Defs | Key]: K extends keyof Defs
? Defs[K]
: RouteDefinition<ActionResult, Match>;
},
AnyFlag,
ExactFlag,
Match
Expand Down

0 comments on commit cae6bb6

Please sign in to comment.