-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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.reduce doesn't work #44063
Comments
The example code should be here as plain text, and phrases like "doesn't work" and "works" aren't really descriptive enough to do anybody much good. Could you make an edit? Note that this seems to be a duplicate of or strongly related to #36390; that issue is closed as fixed, although the problem with |
I think what you want is this (which has two edits) TEST_LIST.map((testListItem) => {
const options = testListItem.options;
(options as IBaseOption[]).reduce<ValueType[]>((acc, option) => {
if(option.parentValue) {
acc.push(option.parentValue)
}
return acc;
}, []);
}) There's no typesafe way for TS to collapse the different |
But one question reading comments above: considering options as |
I poked around in the files of #31023, which fixed .map() on unions of array types (closing #36390), and found this comment in the test suite: which indicates that .reduce() not working was a known limitation. @weswigham β any chance you already have an issue tracking that somewhere, or is this ticket fine? I've also checked some other common array methods and created a new issue to track the ones that aren't working. |
This issue has been marked as 'Unactionable' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Bug Report
π Search Terms
Array.reduce
Array.reduce doesn't work
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
TS throws error "This expression is not callable."
π Expected behavior
TS should let me iterate through array (I tell it the type is either array of IBaseOption OR array of ISelectOption (not an array of mixed types). In any case the variable is an array and those methods should be callable.
The text was updated successfully, but these errors were encountered: