mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
Extract complex type as type alias
This commit is contained in:
parent
76d04ee277
commit
09bc0f1b60
@ -41,7 +41,7 @@ export class Navigation<T> {
|
||||
return this._path;
|
||||
}
|
||||
|
||||
push<K extends keyof T>(type: K, ...value: T[K] extends true? [(undefined | true)?]: [T[K]]): void {
|
||||
push<K extends keyof T>(type: K, ...value: OptionalValue<T[K]>): void {
|
||||
const newPath = this.path.with(new Segment(type, ...value));
|
||||
if (newPath) {
|
||||
this.applyPath(newPath);
|
||||
@ -93,7 +93,7 @@ export class Navigation<T> {
|
||||
return new Path(segments, this._allowsChild);
|
||||
}
|
||||
|
||||
segment<K extends keyof T>(type: K, ...value: T[K] extends true? [(undefined | true)?]: [T[K]]): Segment<T> {
|
||||
segment<K extends keyof T>(type: K, ...value: OptionalValue<T[K]>): Segment<T> {
|
||||
return new Segment(type, ...value);
|
||||
}
|
||||
}
|
||||
@ -119,7 +119,7 @@ function segmentValueEqual<T>(a?: T[keyof T], b?: T[keyof T]): boolean {
|
||||
export class Segment<T, K extends keyof T = any> {
|
||||
public value: T[K];
|
||||
|
||||
constructor(public type: K, ...value: T[K] extends true? [(undefined | true)?]: [T[K]]) {
|
||||
constructor(public type: K, ...value: OptionalValue<T[K]>) {
|
||||
this.value = (value[0] === undefined ? true : value[0]) as unknown as T[K];
|
||||
}
|
||||
}
|
||||
|
@ -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<SegmentType, "rooms">, roomId: stri
|
||||
}
|
||||
|
||||
// todo-self: verify code change here is okay
|
||||
function pushRightPanelSegment<T extends keyof SegmentType>(array: Segment<SegmentType>[], segment: T, ...value: SegmentType[T] extends true? [(undefined | true)?]: [SegmentType[T]]) {
|
||||
function pushRightPanelSegment<T extends keyof SegmentType>(array: Segment<SegmentType>[], segment: T, ...value: OptionalValue<SegmentType[T]>) {
|
||||
array.push(new Segment("right-panel"));
|
||||
array.push(new Segment(segment, ...value));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user