-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Array predicates should not have to return boolean #27509
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
Array predicates should not have to return boolean #27509
Conversation
- Adds tests to above change
- Adds tests to above change
- Adds tests to above change
- Adds tests to above change
Test bench: function filter1<T>(arr: T[], pred: (arg: T) => any) { }
function filter2<T>(arr: T[], pred: (arg: T) => unknown) { }
function filter3<T>(arr: T[], pred: (arg: T) => boolean) { }
function filter4<T>(arr: T[], pred: (arg: T) => {}) { }
function filter5<T>(arr: T[], pred: (arg: T) => {} | null | undefined) { }
const arr = [0];
filter1(arr, i => { });
filter1(arr, i => "");
filter1(arr, i => { return; });
filter1(arr, i => { return null; });
filter1(arr, i => { return undefined; });
filter2(arr, i => { });
filter2(arr, i => "");
filter2(arr, i => { return; });
filter2(arr, i => { return null; });
filter2(arr, i => { return undefined; });
filter3(arr, i => { });
filter3(arr, i => "");
filter3(arr, i => { return; });
filter3(arr, i => { return null; });
filter3(arr, i => { return undefined; });
filter4(arr, i => { });
filter4(arr, i => "");
filter4(arr, i => { return; });
filter4(arr, i => { return null; });
filter4(arr, i => { return undefined; });
filter5(arr, i => { });
filter5(arr, i => "");
filter5(arr, i => { return; });
filter5(arr, i => { return null; });
filter5(arr, i => { return undefined; }); I think |
I agree, but it would still be slightly more restrictive than the filter function in plain JavaScript. Following the discussion in #5850 it sounds like Should I change the |
…r array functions find, findIndex, some and every - Extends test cases for previous commits in this branch, to better reflect the expected behavior
I'm going to take this to the design meeting |
This one's a bit out of date and we'd prefer a change to |
Changes predicate return type from
boolean
toany
for array operationsfind
,findIndex
,some
andevery
, such that the behavior matches that of thefilter
operation.Fixes #27496