Conversation
types/filter.d.ts
Outdated
| }; | ||
|
|
||
| // filter(() => boolean) | ||
| // filter(() => boolean, list) |
There was a problem hiding this comment.
// filter(() => boolean) was correct as is. More accurately it's // filter(() => boolean)(list | dict)
d004287 to
cf6a1f1
Compare
|
@Harris-Miller thanks for feedback, fixed and rebased |
| }; | ||
|
|
||
| // filter(() => boolean) | ||
| // filter(() => boolean)(list | dict) |
There was a problem hiding this comment.
| // filter(() => boolean)(list | dict) | |
| // filter(() => boolean) |
| <K>(map: Map<K, T>): Map<K, T>; | ||
| <P extends T, C extends readonly P[] | Record<string, P>>(collection: C): C; |
There was a problem hiding this comment.
| <K>(map: Map<K, T>): Map<K, T>; | |
| <P extends T, C extends readonly P[] | Record<string, P>>(collection: C): C; | |
| // filter(() => boolean)(map) | |
| <K>(map: Map<K, T>): Map<K, T>; | |
| // filter(() => boolean)(list | dict) | |
| <P extends T, C extends readonly P[] | Record<string, P>>(collection: C): C; |
| @@ -10,10 +10,18 @@ export function filter<A, P extends A>( | |||
| <B extends A>(list: readonly B[]): P[]; | |||
There was a problem hiding this comment.
Github doesn't let you add suggests to unchanged code, but you need to add type support for Map here too. This whole things should be:
// filter(() => narrow)
export function filter<A, P extends A>(
pred: (val: A) => val is P,
): {
// filter(() => narrow)(map)
<K, B extends A>(map: Map<K, B>): Map<K, P>;
// if we put `Record<string, A>` first, it will actually pic`A[]` as well
// so it needs to go first
// filter(() => narrow)(list)
<B extends A>(list: readonly B[]): P[];
// filter(() => narrow)(dict)
<B extends A>(dict: Record<string, B>): Record<string, P>;
// but we also want `A[]` to be the default when doing `pipe(filter(fn))`, so it also needs to be last
// filter(() => narrow)(list | dict)
<B extends A>(list: readonly B[]): P[];
};| // filter(() => narrow)(dist) | ||
| expectType<Map<string, string>>(filter(isNotNil, new Map<string, string | undefined>())); | ||
| expectType<Map<string, number>>(filter(gt5, new Map<string, number>())); |
There was a problem hiding this comment.
First, these tests are for // filter(() => narrow, map)
Second, you need to be far more exhaustive with your test additions. This file has test coverage for all curry varieties and argument type overloads. You added support for a new argument type, so you need to add tests for each curry call variation
For ramda/ramda#3507