iterare
iterare copied to clipboard
[bug][filter] type definition
for https://github.com/felixfbecker/iterare/blob/master/src/iterate.ts
now:
filter(predicate: (element: T) => boolean): IteratorWithOperators<T>
filter<R extends T>(predicate: (element: T) => element is R): IteratorWithOperators<R>
filter(predicate: (element: T) => boolean): IteratorWithOperators<T> {
return new IteratorWithOperators(new FilterIterator(this.source, predicate))
}
expected:
filter<R extends T>(predicate: (element: T) => element is R): IteratorWithOperators<R>
filter(predicate: (element: T) => boolean): IteratorWithOperators<T>
filter(predicate: (element: T) => boolean): IteratorWithOperators<T> {
return new IteratorWithOperators(new FilterIterator(this.source, predicate))
}
the problem is when write codes like this, you may get a wrong type
const foo = [1, 2, 3, null, undefined, 4] // (number | undefined | null)[]
const bar = iterate(foo)
.filter((item): item is NonNullable<typeof item> => item != null)
.toArray()
// now
bar // => (number | undefined | null)[]
// expectecd
bar // => number[]
So the issue is just the order of overloads?
So the issue is just the order of overloads?
yes, i guess () => xx is XX is subset of () => boolean , so The next one will shadow the previous one
So the issue is just the order of overloads?
how is it going? I'd like to send a PR to fix this.but I got a problem when writing test
this code won't fail tests, which is meaningless.
I found to testing types which require other tools like tsd.I also would like to import this pkg for testing types, but I like to konw how you solve it?
https://github.com/dsherret/conditional-type-checks