Skip to content

fix(typings): Use overloading instead of union type for typings filter, find, first, last. #2164

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

Closed
wants to merge 2 commits into from

Conversation

tetsuharuohzeki
Copy link
Contributor

@tetsuharuohzeki tetsuharuohzeki commented Nov 30, 2016

Description

Drawback

  • We would need specify type parameters to their methods explicitly if we'd like to narrow the type via predicate as type guarde function in some cases.
    • However, I don't think this is a serious problem because we can avoid this drawback with specifying actual types only.
    • And this changes makes our typings more similar to TypeScript's Array methods.

Related issue (if exists)

@coveralls
Copy link

coveralls commented Nov 30, 2016

Coverage Status

Coverage remained the same at 97.686% when pulling 739593f on saneyuki:revert-2119 into 128fb9c on ReactiveX:master.

@tetsuharuohzeki
Copy link
Contributor Author

We would need specify type parameters to their methods explicitly if we'd like to narrow the type via predicate as type guarde function in some cases.

You can see the diff

@tetsuharuohzeki
Copy link
Contributor Author

@kwonoj @david-driscoll

How do you think about this?

@david-driscoll
Copy link
Member

That was my thought for the solution as well.

I have one idea... I need to validate first, I'll check that right now.

@david-driscoll
Copy link
Member

Nope, that didn't work sadly.

We can solve the guard case, or we can solve the much more common case. I would argue that it makes more sense to fix the common case.

LGTM 👍

Copy link
Member

@benlesh benlesh left a comment

Choose a reason for hiding this comment

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

remove the tslint:disable comments, and actually use the variables with something like expect(), even if it's obvious like const x = 1; expect(x).to.equal(1)

});

it('should not be compile error', () => {
// tslint:disable no-unused-variable
Copy link
Member

Choose a reason for hiding this comment

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

It's possible that a later version of TypeScript compiler might completely remove code related to unused variables as an optimization. I'm completely speculating, but it might be worth using expect() to set some obvious assertions around the variables you're not using, and remove these tslint:disable comments.

@rob3c rob3c mentioned this pull request Dec 3, 2016
@rob3c
Copy link
Contributor

rob3c commented Dec 3, 2016

Oops - sorry, guys! I only found out about this today, but I put together what I hope is a fix for this that'll let us keep the new support without breaking the previous behavior.

Please take a peek at #2170 before fully reverting it with this PR. I seem to have covered the concerns in #2163, but maybe there's something else that I missed.

…r, find, first, last.

Abstract
------------
- This fixes ReactiveX#2163
  by reverts commit 922d04e.
  - So this reverts ReactiveX#2119 sadly.

Drawback
---------
- We would need specify type parameters to their method
  explicitly if we'd like to narrow the type via `predicate` as type
  guarde function.
  - However, I don't think this is a serious problem because
    we can avoid this drawback with specifying actual types only.
  - And this changes makes our typings more similar to [TypeScript's
    Array
    methods](https://github.com/Microsoft/TypeScript/blob/master/lib/lib.es5.d.ts#L1086-L1097).
@coveralls
Copy link

coveralls commented Dec 6, 2016

Coverage Status

Coverage remained the same at 97.686% when pulling 739593f on saneyuki:revert-2119 into 128fb9c on ReactiveX:master.

@tetsuharuohzeki
Copy link
Contributor Author

@Blesh @jayphelps

@kwonoj
Copy link
Member

kwonoj commented Dec 7, 2016

@saneyuki , appreciate for effort for creating PR. as original author provided fix in #2170 and quick checking seems it correctly addresses problems, those PR has been checked in instead of taking it out. Let me close this PR in favor of #2170 . Thanks again!

@kwonoj kwonoj closed this Dec 7, 2016
@tetsuharuohzeki tetsuharuohzeki deleted the revert-2119 branch December 7, 2016 02:55
@tetsuharuohzeki
Copy link
Contributor Author

@kwonoj

OK. I agree to close this ;-)

@lock
Copy link

lock bot commented Jun 6, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type lost when using interfaces with filter, find, first, last
6 participants