Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add type predicate overloading of 'filter' function #11

Merged
merged 2 commits into from
Nov 22, 2021

Conversation

jbl428
Copy link
Contributor

@jbl428 jbl428 commented Nov 20, 2021

To make type predicate work as expected in filter function.
I forgot to add this one in previous PR 😄

declare function isString(s: unknown): s is string;

const res5 = filter(isString, [1, "a", true]); // IterableIterator<string>

@@ -92,14 +92,14 @@ function uniqBy<A extends Iterable<unknown> | AsyncIterable<unknown>, B>(

if (isIterable(iterable)) {
return pipe(
iterable as Iterable<IterableInfer<A>>,
iterable,
filter((a) => pipe1(f(a), checkAndAdd)),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I change this line to remove type error.
It was caused by following definition.

function filter<
  A extends Iterable<unknown> | AsyncIterable<unknown>,
  B extends IterableInfer<A>,
>(
  f: (a: IterableInfer<A>) => a is B,
): (iterable: A) => ReturnIterableIteratorType<A, B>;

I can not sure it is right definition.

@@ -85,7 +85,7 @@
"prettier --write",
"git add"
],
"*.json": [
"*.(json|md)": [
Copy link
Contributor Author

@jbl428 jbl428 Nov 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pre commit hook did not check markdown files but CI does.
so CI failed if someone edit markdown file and did not run prettier.

Copy link
Member

@ppeeou ppeeou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We didn't think of this part Thank you for your contribution👍

Copy link
Collaborator

@shine1594 shine1594 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

@shine1594 shine1594 merged commit e81ac3a into marpple:main Nov 22, 2021
@jbl428 jbl428 deleted the add-overload-type branch December 30, 2021 01:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants