We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7cbc491 commit 238631fCopy full SHA for 238631f
src/helpers.ts
@@ -8,11 +8,15 @@ import { t } from './lang';
8
* @param objects The array to split.
9
* @param key The key of T.
10
*/
11
-export function splitBy<T>(objects: T[], key: keyof T): T[][] {
12
- const map = {} as Record<string | number, T[]>;
+export function splitBy<
+ T extends Record<string, unknown>,
13
+ K extends keyof T,
14
+ U extends Record<K, string | number>
15
+>(objects: U[], key: K): U[][] {
16
+ const map = {} as Record<string | number, U[]>;
17
18
for (const obj of objects) {
- const commonValue = obj[key] as string | number;
19
+ const commonValue = obj[key];
20
21
if (!map[commonValue])
22
map[commonValue] = [];
0 commit comments