diff --git a/src/domain/navigation/Navigation.ts b/src/domain/navigation/Navigation.ts index cb6637a9..dfd69bd1 100644 --- a/src/domain/navigation/Navigation.ts +++ b/src/domain/navigation/Navigation.ts @@ -34,6 +34,7 @@ type SegmentType = { "member": string; }; + export class Navigation { private readonly _allowsChild: AllowsChild; private _path: Path; @@ -54,8 +55,8 @@ export class Navigation { return this._path; } - push(type, value = undefined): void { - const newPath = this.path.with(new Segment(type, value)); + push(type: K, ...value: T[K] extends true? [undefined?]: [T[K]]): void { + const newPath = this.path.with(new Segment(type, ...value)); if (newPath) { this.applyPath(newPath); } @@ -106,8 +107,8 @@ export class Navigation { return new Path(segments, this._allowsChild); } - segment(type: K, value: T[K]): Segment { - return new Segment(type, value); + segment(type: K, ...value: T[K] extends true? [undefined?]: [T[K]]): Segment { + return new Segment(type, ...value); } } @@ -130,10 +131,11 @@ function segmentValueEqual(a?: T[keyof T], b?: T[keyof T]): boolean { export class Segment { - constructor( - public type: K, - public value: T[K] = (value === undefined ? true : value) as T[K] - ) {} + public value: T[K]; + + constructor(public type: K, ...value: T[K] extends true? [undefined?]: [T[K]]) { + this.value = (value[0] === undefined ? true : value[0]) as unknown as T[K]; + } } class Path {