1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-25 16:49:18 -05:00

fix: Object.groupBy return type should be a partial (#21680)

Signed-off-by: Joel Walker <joelwalker1995@gmail.com>
This commit is contained in:
Joel Walker 2023-12-29 15:41:40 -08:00 committed by GitHub
parent fa3a12a805
commit 4740929950
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View file

@ -196,6 +196,12 @@ Deno.test(function objectGroupBy() {
});
});
Deno.test(function objectGroupByEmpty() {
const empty: string[] = [];
const result = Object.groupBy(empty, () => "abc");
assertEquals(result.abc, undefined);
});
// Taken from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/groupBy#examples
Deno.test(function mapGroupBy() {
const inventory = [

View file

@ -21,7 +21,7 @@ interface ObjectConstructor {
groupBy<Item, Key extends PropertyKey>(
items: Iterable<Item>,
keySelector: (item: Item, index: number) => Key,
): Record<Key, Item[]>;
): Partial<Record<Key, Item[]>>;
}
interface MapConstructor {