1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-29 16:30:56 -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 Bartek Iwańczuk
parent f9df3833c7
commit a267225a17
No known key found for this signature in database
GPG key ID: 0C6BCDDC3B3AD750
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 // Taken from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/groupBy#examples
Deno.test(function mapGroupBy() { Deno.test(function mapGroupBy() {
const inventory = [ const inventory = [

View file

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