Skip to content

Commit d004287

Browse files
Apply suggestions from code review
Co-authored-by: Harris Miller <[email protected]>
1 parent 84f3364 commit d004287

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

test/filter.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,5 @@ expectType<Record<string, string>>(filter(isNotNil, {} as Dict));
9393

9494

9595
// filter(() => narrow)(dist)
96-
expectType<Map<string, string>>(filter(isNotNil, new Map() as Map<string, string | undefined>));
97-
expectType<Map<string, number>>(filter(gt5, new Map() as Map<string, number>));
96+
expectType<Map<string, string>>(filter(isNotNil, new Map<string, string | undefined>()));
97+
expectType<Map<string, number>>(filter(gt5, new Map<string, number>()));

types/filter.d.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ export function filter<A, P extends A>(
1313
// filter(() => boolean, list)
1414
export function filter<T>(
1515
pred: (value: T) => boolean,
16-
): <P extends T, C extends readonly P[] | Record<string, P>>(collection: C) => C;
16+
): {
17+
<K>(map: Map<K, T>): Map<K, T>;
18+
<P extends T, C extends readonly P[] | Record<string, P>>(collection: C): C;
19+
};
1720

1821
// filter(() => narrow, map)
19-
export function filter<K, T, P extends T>(pred: (val: T) => val is P, map: readonly Map<K, T>): Map<K, P>;
22+
export function filter<K, T, P extends T>(pred: (val: T) => val is P, map: Map<K, T>): Map<K, P>;
2023
// filter(() => boolean, map)
21-
export function filter<K, T>(pred: (val: T) => boolean, map: readonly Map<K, T>): Map<K, T>;
24+
export function filter<K, T>(pred: (val: T) => boolean, map: Map<K, T>): Map<K, T>;
2225

2326
// filter(() => narrow, list) - readonly T[] falls into Record<string T> for some reason, so list needs to come first
2427
export function filter<T, P extends T>(pred: (val: T) => val is P, list: readonly T[]): P[];

0 commit comments

Comments
 (0)