-
Notifications
You must be signed in to change notification settings - Fork 3k
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
manual typings for bindCallback.create #1086
Conversation
d434eef
to
91a349a
Compare
@david-driscoll I think you proposed this at an inopportune time (before the holidays). Do my heavy TypeScript users have any opinions? @robwormald @jeffbcross @kwonoj |
Discussion at the moment makes this discussion pause until #1077 is landed in codebase, to separate scope of changes. Shortly, I still need spend some time to review these changes. |
Just to ensure, PR intended to be checked in is #1087, this PR shows handcrafted changes to compare with original PR. |
the better the types in the distribution, the better, as far as i'm concerned. i'll take an extra few kb's of npm download for better intellisense. Up to y'all in terms of maintainability. |
77a7c52
to
ab73d44
Compare
1c2c4a0
to
5cbeb5e
Compare
After doing some work today, I'm thinking this branch might be the preferred method, I added some "unit tests" as well (basically to ensure that things compile as expected). |
meaning between #1087 and this?
Would you able to separate those? You may able to see there are pending PR in discussion #826 #667 for enabling test against type definitions, haven't concluded which way'll go. If your changes separated, that can be considerable option too. |
Correct, this over #1087, it's a little more manual work, but the quality will probably be better. If you look at |
yes, aware of those. Current discussion regarding test is about organization of test since it's testing definition only - so it'll be matter of trying to use existing PR's mechanism, or following your PR's mechanism to invoke those. Once it's decided, test can be added fairly quickly. |
a276fa4
to
846bcca
Compare
@kwonoj done! |
Thanks! I still need to look changes to add some inputs.. (my work-for-pay-bill blocks me, sorry for late response) |
@@ -5,6 +5,6 @@ | |||
import {Observable} from '../../Observable'; | |||
import {combineLatest} from '../../operator/combineLatest'; | |||
|
|||
Observable.prototype.combineLatest = combineLatest; | |||
Observable.prototype.combineLatest = <any>combineLatest; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this patch operator's now auto generated, so instead of changing this script need to be updated - is that correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, because combineLatest
(the method) no longer has the same definition as combineLatest
the prototype method.
I plan to update the script to add this in, and that's when I found out that the generation script didn't work the other day.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmn. Makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated this in the last third commit as something separate from the other work. (Hence the larger number of files changed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this should be needed. The implementation function should be assignable to the interface. If it doesn't do that, it means there's some overloads in the interface that the implementation isn't equipped to handle.
In the case of combineLatest
, the interface is advertising to users that they can pass in iterators, promises or arrays wherever observables are expected, however the function isn't written to expect these and will explode. This is causing the assignability error, which is a good thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend narrowing ObservableInput<T>
to just Observable<T>
until we can figure out a way to generically deal with iterators, arrays and promises in the actual implementations (which would be absolutely magical!)
Let me ask few questions as 'newcomer' point of view, let's say I'm completely new to codebase and compose new operator require similar function signatures
There might be some other questions I could possible missing. |
|
It only apply to methods that have a method that has some sort of applied / combined output or input. Which is actually only a few, but they are the important ones to capture, because it makes type inference that much better. Exaples are The only other most common case is methods with an optional selector. You'd want one overload without the selector, because generally those return the incoming type |
I don't now what do you guys think but I'd prefer to split this into two separate commits: one for |
a36f7ae
to
5670c32
Compare
@kwonoj rebased! I was able to eliminate the calls, so that's already been removed from the changes. |
@david-driscoll Right now the implementation for I'd suggest narrowing |
@masaeedu I don't see any constraints in the code that would cause any compilation problems. To validate I merged with your changes (which merge cleanly btw! ❤️ git). Do you have a specific example where you have seen issues pop in? |
That's odd, it doesn't compile for me. The changes I'm making are to remove |
Want to push your local branch and I'll check it out and see if I can see what you're seeing? |
@david-driscoll Yup, here you go: https://github.com/masaeedu/RxJS/tree/typings-option-a. Look at the error for |
Found the problem. Your changes removed Now that said the real solution isn't actually anything that is wrong, the typings are just incorrect. Currently ArrayObservable is typed like The best way I see to type around that is something like:
This produces the effect that we're looking for. In call cases of |
@david-driscoll You have to remove at least |
The reason I think the error is understandable and correct is that an |
Two different problems.
|
Ah, I wasn't aware I actually have a version of
I would just need to update this to:
I'll update stuff in my branch. |
I've already marked this as lgtm & latest update removes |
It looks like there are some merge conflicts... @david-driscoll can you rebase this? @kwonoj, feel free to merge this whenever you think is appropriate if you feel this is an improvement to our typings. |
Will do. I've already completed reviewing this and so far I believe good to check in. I'll do it myself once it's rebased. |
lgtm, for what it's worth. Is this going to be a pattern that is followed uniformly for all the operators or just for the ones with complicated type signatures? |
@david-driscoll , I'll check this in once it's rebased. (Gentle reminder, not poking 😉 ) |
5670c32
to
91bc0e8
Compare
export function combineLatestStatic<T, R>(...observables: Array<any | Observable<any> | | ||
Array<Observable<any>> | | ||
/* tslint:disable:max-line-length */ | ||
export function combineLatestStatic<T>(v1: ObservableInput<T>): Observable<[T]>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since these have been merged, I added definitions for combineLatestStatic
that mirror the signatures.
@kwonoj rebased. |
Thanks! I'll check this in. |
Merged with 7c9547a, appreciate for huge effort @david-driscoll 😄 |
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. |
Comparing against generation of types to spur on discussion of the best approach. I picked a single file here just as an example case. See #1087
As a reference for TypeScript itself, these typings can't be simplified much more without losing the enhanced experience of operating against them.
microsoft/TypeScript#5453 may be the answer, not sure if it answers all the possible use cases. It is currently on the road map for 2.0.
I realize there will be tons of opinions my only goal is to make the TypeScript experience with RxJS5 as good as we have gotten the experience in RxJS4.