From 1ff7e164ff1e00b7a9a601690a3681c59c68a738 Mon Sep 17 00:00:00 2001 From: eternal-flame-AD Date: Mon, 2 Sep 2024 02:37:51 -0500 Subject: [PATCH] type inference helpers for converting options to tracks Signed-off-by: eternal-flame-AD --- js/igv.d.ts | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/js/igv.d.ts b/js/igv.d.ts index 0683219ae..b9dbf4ff3 100644 --- a/js/igv.d.ts +++ b/js/igv.d.ts @@ -6,7 +6,8 @@ declare class Opaque { private readonly __opaque_brand: N; } -export type TrackLoad = Tracks.TrackCommonOptions & +export type TrackLoad = + Tracks.TrackCommonOptions & ((Tracks.AnnotationTrackOptions & Tracks.TypeFormatPair<'annotation', Tracks.AnnotationFormat>) | (Tracks.WigTrackOptions & Tracks.TypeFormatPair<'wig', Tracks.WigFormat>) | (Tracks.WigMergedTrackOptions & { type: 'merged' }) | @@ -15,8 +16,20 @@ export type TrackLoad = Tracks.TrackCommonOptions & (Tracks.SegTrackOptions & Tracks.TypeFormatPair<'seg', Tracks.SegTrackFormat>) | (Tracks.CnvPyTorTrackOptions & Tracks.TypeFormatPair<'cnvpytor', Tracks.CnvPyTorFormat>)); +export type TrackOf = + T extends "annotation" ? Tracks.Track : + T extends "alignment" ? Tracks.AlignmentTrack : + T extends "variant" ? Tracks.Track : + T extends "seg" ? Tracks.Track : + T extends "cnvpytor" ? Tracks.Track : + T extends "wig" ? Tracks.Track : + T extends "merged" ? Tracks.Track : + never; + +export type TrackOfLoad = K extends { type: infer T } ? T extends string ? TrackOf : never : never; + export namespace Tracks { - export declare class Track { }; \ + export class Track { } export interface TypeFormatPair { type?: K; @@ -314,7 +327,6 @@ export namespace Tracks { "strand" | "firstOfPairStrand" | "pairOrientation" | "mateChr" | "chimeric" | "supplementary" | "readOrder" | AlignmentBy; samplingWindowSize?: number; samplingDepth?: number; - alignmentRowHeight?: number; readGroup?: string; sort: AlignmentSortOptions; filter: { @@ -347,17 +359,17 @@ export namespace Tracks { ) - export declare class AlignmentTrack extends Track { + class AlignmentTrack extends Track { setHighlightedReads(readNames: string[], color: string): void; sort(options: AlignmentSortOptions): void; - }; + } } type Nucleotide = 'A' | 'C' | 'G' | 'T' | 'N'; type AnnotationFormat = 'bed' | 'gff3' | 'gtf' | 'genePred' | 'genePredExt' | 'peaks' | 'narrowPeak' | 'broadPeak' | 'bigBed' | 'bedpe'; interface GenomeNoRef { - genome: string; + genome: HostedGenomes | (string & {}); reference?: never; } @@ -520,17 +532,18 @@ interface DefineROI { color: string; } + declare class _Browser { currentLoci(): string[] | string; loadGenome(genome: string | ReferenceGenome): Promise; loadSessionObject(session: Opaque<'igv.js session JSON'>): void; loadSession(session: string): void; // TODO: check the return type - loadTrack(track: TrackLoad): Promise; + loadTrack(track: TrackLoad): Promise; loadSampleInfo({ url: string }): void; - findTracks(func: (track: Track) => boolean): Track[]; - findTracks(property: string, value: any): Track[]; - removeTrack(track: Track): void; + findTracks(func: (track: Tracks.Track) => boolean): Tracks.Track[]; + findTracks(property: string, value: any): Tracks.Track[]; + removeTrack(track: Tracks.Track): void; removeTrackByName(trackName: string): void; loadROI(roi: DefineROI | DefineROI[]): void; clearROIs(): void;