summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Walker <joel@walker9.net>2023-12-29 15:41:40 -0800
committerGitHub <noreply@github.com>2023-12-30 00:41:40 +0100
commit4740929950b7043da51a0b717c9e6e1116791f02 (patch)
treeedc6c2476a17218473eaefb20413c8b0bdbdea1b
parentfa3a12a8056836e7ab337c4af1eabcb0e8edade2 (diff)
fix: `Object.groupBy` return type should be a partial (#21680)
Signed-off-by: Joel Walker <joelwalker1995@gmail.com>
-rw-r--r--cli/tests/unit/globals_test.ts6
-rw-r--r--cli/tsc/dts/lib.esnext.object.d.ts2
2 files changed, 7 insertions, 1 deletions
diff --git a/cli/tests/unit/globals_test.ts b/cli/tests/unit/globals_test.ts
index 9f7f77644..1bb5b50f0 100644
--- a/cli/tests/unit/globals_test.ts
+++ b/cli/tests/unit/globals_test.ts
@@ -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 = [
diff --git a/cli/tsc/dts/lib.esnext.object.d.ts b/cli/tsc/dts/lib.esnext.object.d.ts
index 130f2fc9f..3440d8d0d 100644
--- a/cli/tsc/dts/lib.esnext.object.d.ts
+++ b/cli/tsc/dts/lib.esnext.object.d.ts
@@ -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 {