diff --git a/apps/rep/app.ts b/apps/rep/app.ts index d1dd67179..14fb45482 100644 --- a/apps/rep/app.ts +++ b/apps/rep/app.ts @@ -196,7 +196,7 @@ const layout = new L({ ] } ] -}, {lazy: true}); +} as const, {lazy: true}); class State { paused: boolean = true; @@ -248,7 +248,7 @@ class State { } } -const repToLabel = (i: number, id: string) => { +const repToLabel = (i: number, id: "cur" | "next") => { const rep = reps[i]; if(rep) layout[`${id}_name`]!.label = `${rep.label} / ${msToMinSec(rep.dur)}`; @@ -256,7 +256,7 @@ const repToLabel = (i: number, id: string) => { emptyLabel(id); }; -const emptyLabel = (id: string) => { +const emptyLabel = (id: "cur" | "next") => { layout[`${id}_name`]!.label = " / 0m"; }; diff --git a/typescript/types/layout.d.ts b/typescript/types/layout.d.ts index 167ede29d..55ddd7135 100644 --- a/typescript/types/layout.d.ts +++ b/typescript/types/layout.d.ts @@ -1,10 +1,13 @@ type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; +type UnionToIntersection = + (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never + type ExtractIds = [Depth] extends [never] ? never - : (T extends { id: infer Id extends string } - ? { [k in Id]: T } + : (T extends { id?: infer Id extends string } + ? { [k in Id]: { -readonly [P in keyof T]: T[P] extends string ? string : T[P] } } : never) | ( @@ -15,7 +18,7 @@ type ExtractIds = declare module Layout { type Layouter = - ExtractIds + UnionToIntersection> & { // these actually change T @@ -31,6 +34,7 @@ declare module Layout { setUI(): void; }; + // Note: you must use new Layout({...} as const) to have ids inferred var Layout: { new ( hier: T,