diff --git a/test/filter.test.ts b/test/filter.test.ts index b4c5279..776b941 100644 --- a/test/filter.test.ts +++ b/test/filter.test.ts @@ -90,3 +90,8 @@ expectType<(number | undefined)[]>(filter(x => x != null, [] as (number | undefi // filter(() => narrow, dist) // no need for type annotations when using full signature expectType>(filter(isNotNil, {} as Dict)); + + +// filter(() => narrow)(dist) +expectType>(filter(isNotNil, new Map())); +expectType>(filter(gt5, new Map())); diff --git a/types/filter.d.ts b/types/filter.d.ts index 8e47ed2..5ad1af9 100644 --- a/types/filter.d.ts +++ b/types/filter.d.ts @@ -10,10 +10,18 @@ export function filter( (list: readonly B[]): P[]; }; -// filter(() => boolean) +// filter(() => boolean)(list | dict) export function filter( pred: (value: T) => boolean, -):

>(collection: C) => C; +): { + (map: Map): Map; +

>(collection: C): C; +}; + +// filter(() => narrow, map) +export function filter(pred: (val: T) => val is P, map: Map): Map; +// filter(() => boolean, map) +export function filter(pred: (val: T) => boolean, map: Map): Map; // filter(() => narrow, list) - readonly T[] falls into Record for some reason, so list needs to come first export function filter(pred: (val: T) => val is P, list: readonly T[]): P[];