From 09bc0f1b603323f8dbfce2a7c832657842e5acb1 Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Tue, 22 Feb 2022 13:30:37 +0530 Subject: [PATCH] Extract complex type as type alias --- src/domain/navigation/Navigation.ts | 6 +++--- src/domain/navigation/index.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/domain/navigation/Navigation.ts b/src/domain/navigation/Navigation.ts index 5157f86c..6cde56c2 100644 --- a/src/domain/navigation/Navigation.ts +++ b/src/domain/navigation/Navigation.ts @@ -41,7 +41,7 @@ export class Navigation { return this._path; } - push(type: K, ...value: T[K] extends true? [(undefined | true)?]: [T[K]]): void { + push(type: K, ...value: OptionalValue): void { const newPath = this.path.with(new Segment(type, ...value)); if (newPath) { this.applyPath(newPath); @@ -93,7 +93,7 @@ export class Navigation { return new Path(segments, this._allowsChild); } - segment(type: K, ...value: T[K] extends true? [(undefined | true)?]: [T[K]]): Segment { + segment(type: K, ...value: OptionalValue): Segment { return new Segment(type, ...value); } } @@ -119,7 +119,7 @@ function segmentValueEqual(a?: T[keyof T], b?: T[keyof T]): boolean { export class Segment { public value: T[K]; - constructor(public type: K, ...value: T[K] extends true? [(undefined | true)?]: [T[K]]) { + constructor(public type: K, ...value: OptionalValue) { this.value = (value[0] === undefined ? true : value[0]) as unknown as T[K]; } } diff --git a/src/domain/navigation/index.ts b/src/domain/navigation/index.ts index bcce8936..06920e61 100644 --- a/src/domain/navigation/index.ts +++ b/src/domain/navigation/index.ts @@ -16,7 +16,7 @@ limitations under the License. import {Navigation, Segment} from "./Navigation"; import {URLRouter} from "./URLRouter"; -import type {Path} from "./Navigation"; +import type {Path, OptionalValue} from "./Navigation"; export type SegmentType = { "login": true; @@ -107,7 +107,7 @@ function roomsSegmentWithRoom(rooms: Segment, roomId: stri } // todo-self: verify code change here is okay -function pushRightPanelSegment(array: Segment[], segment: T, ...value: SegmentType[T] extends true? [(undefined | true)?]: [SegmentType[T]]) { +function pushRightPanelSegment(array: Segment[], segment: T, ...value: OptionalValue) { array.push(new Segment("right-panel")); array.push(new Segment(segment, ...value)); }