You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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:
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: