Skip to content

Commit 92ba447

Browse files
committed
cleanup flags usage
1 parent 968a1f8 commit 92ba447

2 files changed

Lines changed: 20 additions & 10 deletions

File tree

frontend/src/ts/collections/results.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { SnapshotResult } from "../constants/default-snapshot";
2525
import { queryClient } from "../queries";
2626
import { baseKey } from "../queries/utils/keys";
2727
import { getSnapshot } from "../states/snapshot";
28+
import { ExactlyOneTrue } from "../utils/types";
2829

2930
export type ResultsQueryState = {
3031
difficulty: SnapshotResult<Mode>["difficulty"][];
@@ -385,16 +386,10 @@ export async function getUserAverage<M extends Mode>(
385386
language: string;
386387
difficulty: Difficulty;
387388
lazyMode: boolean;
388-
} & (
389-
| {
390-
last10Only: boolean;
391-
lastDayOnly?: never;
392-
}
393-
| {
394-
lastDayOnly: boolean;
395-
last10Only?: never;
396-
}
397-
),
389+
} & ExactlyOneTrue<{
390+
last10Only: boolean;
391+
lastDayOnly: boolean;
392+
}>,
398393
): Promise<[number, number]> {
399394
const activeTagIds = getSnapshot()
400395
?.tags.filter((it) => it.active === true)

frontend/src/ts/utils/types.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export type OneOf<T> = {
2+
[K in keyof T]: {
3+
[P in K]: T[P];
4+
} & {
5+
[P in Exclude<keyof T, K>]?: never;
6+
};
7+
}[keyof T];
8+
9+
export type ExactlyOneTrue<T extends Record<string, boolean>> = {
10+
[K in keyof T]: {
11+
[P in K]: true;
12+
} & {
13+
[P in Exclude<keyof T, K>]?: false | never;
14+
};
15+
}[keyof T];

0 commit comments

Comments
 (0)