-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Spy with Jasmine on Store.select Typescript Error: Expected at least 6 arguments, but got 1. #2674
Comments
Hey @greg-md Let us know if you'll have any further questions. |
@alex-okrushko Thanks. I will reuse that, but the typescript declaration still needs to be fixed. Might affect other cases as well. |
@greg-md if you create a typed store this issue should go away. const storeSpy = jasmine.createSpyObj<Store<{foo: any}>>('Store', ['select']);
storeSpy.select.withArgs('foo').and.returnValue(of(null)); |
@timdeschryver it is not, because the problem is not in the typed store. It is in the select<K>(mapFn: (state: T) => K): Observable<K>;
select<K, Props = any>(mapFn: (state: T, props: Props) => K, props: Props): Observable<K>;
select<a extends keyof T>(key: a): Observable<T[a]>;
select<a extends keyof T, b extends keyof T[a]>(key1: a, key2: b): Observable<T[a][b]>;
select<a extends keyof T, b extends keyof T[a], c extends keyof T[a][b]>(key1: a, key2: b, key3: c): Observable<T[a][b][c]>;
select<a extends keyof T, b extends keyof T[a], c extends keyof T[a][b], d extends keyof T[a][b][c]>(key1: a, key2: b, key3: c, key4: d): Observable<T[a][b][c][d]>;
select<a extends keyof T, b extends keyof T[a], c extends keyof T[a][b], d extends keyof T[a][b][c], e extends keyof T[a][b][c][d]>(key1: a, key2: b, key3: c, key4: d, key5: e): Observable<T[a][b][c][d][e]>;
select<a extends keyof T, b extends keyof T[a], c extends keyof T[a][b], d extends keyof T[a][b][c], e extends keyof T[a][b][c][d], f extends keyof T[a][b][c][d][e]>(key1: a, key2: b, key3: c, key4: d, key5: e, key6: f): Observable<T[a][b][c][d][e][f]>;
select<a extends keyof T, b extends keyof T[a], c extends keyof T[a][b], d extends keyof T[a][b][c], e extends keyof T[a][b][c][d], f extends keyof T[a][b][c][d][e], K = any>(key1: a, key2: b, key3: c, key4: d, key5: e, key6: f, ...paths: string[]): Observable<K>; |
Exactly... and that's why you have to type the Store.
|
@timdeschryver Again, the problem is not in the type of the Store(I already used that, just simplified the example in the post) but in how the typescript gets the right declaration(could be a typescript issue as well, not sure). You can try on your local. The error is on arguments count which expects to have |
@greg-md I did try it locally but I receive the following error
|
It seems like this is specific to this issue. The As Alex pointed out, if you want to mock selectors see the docs. |
Closing this one. @greg-md let us know if there are any issues with the recommended approach. |
I am facing the same issue and didn't find a good solution. The problem arises also with My "solutions" aka workarounds so far:
I am not sure, if this is an issue of jasmine or ngrx or Typescript, but it is definitely an issue. @greg-md Did you find a solution yet? Thanks for your support! |
Typescript throws an error if you want to spy on the
Store
class for theselect
method.The problem is in the typescript declaration of the
Store
class which needs to be simplified.Minimal reproduction of the bug/regression with instructions:
The above example throws
Expected at least 6 arguments, but got 1.
Expected behavior:
To be able to use full typings when spying the
Store
class.Versions of NgRx, Angular, Node, affected browser(s) and operating system(s):
The text was updated successfully, but these errors were encountered: