-
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
pairs
observable static function does not infers correctly
#4468
Comments
Had a bit of a play with this over my lunch break... It would be possible to add an overload to pairs with this signature:
This issue with this is that I don't think there's a way for TS to do something similar to The following two overloads cover arrays and "plain" objects (like the one in your example):
Maybe these on their own would be fine? But the signature with
(I don't totally understand the reason why, and whether this is specifically to do with inheritance or not?) So maybe the overloads could be this (the two simple ones first, followed by the more general one):
That way you only fall back to the I don't know what the standard is on typing to unions that are less specific than they "should be"? I'm not hugely read up on type theory, but my understanding is that the Happy to put in a PR with d.ts tests if people think any/all of the above overloads are an improvement? |
Oh and @dkosasih or anyone else that comes across this, right now it looks like the current signature for pairs has no possibility for inference based on arguments, so in 6.3.3 you always need to specify the type param (in your case |
@cartant Is this now with Typescript 3+ possible? |
Closing this because the types in v7 infer correctly: var obj = {
foo: 1,
bar: 2,
baz: 3
};
var source = pairs(obj); // Observable<["foo" | "bar" | "baz", number]> And because rxjs/src/internal/observable/pairs.ts Lines 9 to 12 in 4805a7f
|
Bug Report
Current Behavior
pairs
observable is incorrectly inferred. With the example below the type infers asObservable<[string, {}]>
Expected behavior
It should infer `Observable<[string, number]>
Environment
The text was updated successfully, but these errors were encountered: