-
-
Notifications
You must be signed in to change notification settings - Fork 319
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
Wrong typescript definition for "when" method #317
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there,
I've noticed that the typescript definition for "when" method is wrong
when(condition: boolean, fn: (this: any) => any, defaultFn: (this: any) => any): void;
In reality, the first callback function is most likely gonna return the modified collection, so I assume the return type of the method should be the Collection itself.
The current definition makes the compiler think that chained methods after the "when" method call are called on void, while in reality, it is not true because they are can be called on the modified collection.
E.g.
collect(items).when(condition1, (collection) => collection.push(newItem)).when(condition2, (collection) => collection.pop())
I suppose that void also makes sense sometimes though, so it would be good if the return type is
Collection<Item> | void
Also, the second callback defaultFn should be optional, right now it is required in the typescript definition which also makes the compiler throw warnings.
To sum up, the right definition in my opinion should be next:
when(condition: boolean, fn: (this: any) => any, defaultFn?: (this: any) => any): Collection<Item> | void;
The text was updated successfully, but these errors were encountered: