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

Partition operator example throws typescript error #4419

Closed
1 of 5 tasks
luckylooke opened this issue Dec 12, 2018 · 9 comments
Closed
1 of 5 tasks

Partition operator example throws typescript error #4419

luckylooke opened this issue Dec 12, 2018 · 9 comments
Labels
feature PRs and issues for features help wanted Issues we wouldn't mind assistance with.

Comments

@luckylooke
Copy link

luckylooke commented Dec 12, 2018

Documentation Related To Component:

partition operator
https://www.learnrxjs.io/operators/transformation/partition.html
https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/partition.ts

Please check those that apply

  • typo
  • documentation doesn't exist
  • documentation needs clarification
  • error(s) in example
  • needs example

Description Of The Issue

Opening the example in Stackblitz we are getting typescript error:

Argument of type 'UnaryFunction<Observable<number>, [Observable<number>, Observable<number>]>' is not assignable to parameter of type 'OperatorFunction<any, any>'.
  Type '[Observable<number>, Observable<number>]' is not assignable to type 'Observable<any>'.
    Property '_isScalar' is missing in type '[Observable<number>, Observable<number>]'.

typescript is not complaining about this usage:

const [evens, odds] = partition((val: number) => val % 2 === 0)(source);

Result is the same.

I did not check other example or other online editors but IMHO it would be the same.

I do not have more time for making PR, also I am not sure about whether implementation should be fixed not to confuse typescript or syntax in examples should follow the usage I have provided here.
Sorry.

Thank you for your time and happy coding :)

EDIT:
I have just check jsBin and jsFiddle. I have find out that they are not relevant as they does not support typescript errors. I have tested const num: Number = 'text'; and they both did not complain at all.

@luckylooke
Copy link
Author

I have just found #4119, but I have got the same error in my local project using:

WebStorm 2018.3
Build #WS-183.4284.130, built on November 19, 2018
JRE: 1.8.0_152-release-1343-b15 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 7 6.1
Angular CLI: 7.1.0
Node: 8.11.4
OS: win32 x64
Angular: 7.1.1
... animations, cdk, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.11.0
@angular-devkit/build-angular     0.11.0
@angular-devkit/build-optimizer   0.11.0
@angular-devkit/build-webpack     0.11.0
@angular-devkit/core              7.1.0
@angular-devkit/schematics        7.1.0
@angular/cli                      7.1.0
@ngtools/webpack                  7.1.0
@schematics/angular               7.1.0
@schematics/update                0.11.0
rxjs                              6.3.3
typescript                        3.1.6
webpack                           4.23.1

So now blame who? :D

@jgbpercy
Copy link

jgbpercy commented Dec 13, 2018

That error is the "correct" error. Partition isn't usable within pipe because it's not really an operator, for the reason I explained in 4119:

Partition returns a UnaryFunction, not an OperatorFunction, and pipe only takes OperatorFunctions as arguments. It seems like partition was broken (at least when used in pipe) with the move to pipeable operators, but the clean up work to deprecate/replace it hasn't been priority as partition isn't that widely used. See these issues:

#3797
#2995
#3807

So TS is right to complain about partition being used in pipe, but you can still use partition as a function in its own right, I believe.

(and all the StackBlitz stuff in that thread is resolved now as far as I know, so StackBlitz is giving you an accurate error)

@luckylooke
Copy link
Author

Ok, so then examples should be fixed as they use partition as pipe now:

const [evens, odds] = source.pipe(partition(val => val % 2 === 0));

:)

@benlesh
Copy link
Member

benlesh commented Jan 22, 2019

Partition should really have been a static function, and not an operator. That's the real solution here. And also updating the docs.

TODO:

  1. deprecate the partition operator.
  2. Move it to be a static creation function.
  3. Update the docs and tests accordingly.

@benlesh benlesh added feature PRs and issues for features Next Minor Version labels Jan 22, 2019
@benlesh benlesh added help wanted Issues we wouldn't mind assistance with. and removed target: Next Minor labels Mar 13, 2019
@dkosasih
Copy link
Contributor

dkosasih commented Apr 1, 2019

I'll grab this one if no one has started working on this?

dkosasih added a commit to dkosasih/rxjs that referenced this issue Apr 4, 2019
dkosasih added a commit to dkosasih/rxjs that referenced this issue Apr 4, 2019
dkosasih added a commit to dkosasih/rxjs that referenced this issue Apr 10, 2019
dkosasih added a commit to dkosasih/rxjs that referenced this issue Apr 11, 2019
dkosasih added a commit to dkosasih/rxjs that referenced this issue Apr 11, 2019
dkosasih added a commit to dkosasih/rxjs that referenced this issue Apr 11, 2019
@DaSchTour
Copy link

I wonder who made the statistics that tell that partition isn't widely used. I think there are valid scenarios where you want to have to safetly partitioned Observables where you know that they will never emit the same value. My current solution is really extremely ugly and verbose.

this.isMobileLayout = this.breakpointObserver.observe([Breakpoints.Handset]).pipe(map((result) => result.matches));
        this.isDesktopLayout = this.isMobileLayout.pipe(map((value) => !value));

@szalonna
Copy link

Hello,
Is there any update related to this or what is the current situation with the partition operator?

@jgbpercy
Copy link

partition as an operator used within pipe does not make sense and is deprecated.

partition as a stand alone "creation function" can be used just fine.

@benlesh
Copy link
Member

benlesh commented May 21, 2021

This has been resolved by providing a static partition function and deprecating the operator version for removal in version 8. Other use cases could be met with groupBy. Closing this issue.

import 
const [evens$, odds$] = partition(of(1, 2, 3, 4, 5), n => x % 2 === 0);

@benlesh benlesh closed this as completed May 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature PRs and issues for features help wanted Issues we wouldn't mind assistance with.
Projects
None yet
Development

No branches or pull requests

6 participants