score:0
Accepted answer
reduce
can take a generic to specify what the predicate returns (and the type of the initial value).
Here it is inferred as {}
because of the initial value:
const result = trades.reduce((groupedAccounts, trade) => {
const account = trade.pacct;
if (groupedAccounts[account] == null) groupedAccounts[account] = [];
groupedAccounts[account].push(trade);
return groupedAccounts;
}, {});
You probably want it to be Record<string, TradeData[]>
:
const result = trades.reduce<Record<string, TradeData[]>>((groupedAccounts, trade) => {
const account = trade.pacct;
if (groupedAccounts[account] == null) groupedAccounts[account] = [];
groupedAccounts[account].push(trade);
return groupedAccounts;
}, {});
Source: stackoverflow.com
Related Query
- react typescript error - element implicitly has an any type because expression of type string cant be used to index type {}
- Element implicitly has an 'any' type because expression of type 'string' can't be used to index type React Typescript
- Typescript with React > Element implicitly has an 'any' type because expression of type 'string' can't be used to index
- Typescript error in map(): Element implicitly has an 'any' type because expression of type 'string' can't be used to index type
- Graphql React Typescript error binding element 'currency' implicitly has an 'any' type
- TypeScript - Element implicitly has an 'any' type because expression of type '"storyFile"' can't be used to index type '{}'
- Element implicitly has an 'any' type because expression of type 'any' can't be used to index type '{}' - React Anagram
- error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index 'ModuleType'
- issue typing an object react typescript - Element implicitly has an 'any' type because type'
- Typescript react - Could not find a declaration file for module ''react-materialize'. 'path/to/module-name.js' implicitly has an any type
- error TS2602: JSX element implicitly has type 'any' because the global type 'JSX.Element' does not exist
- binding element 'yyy' implicitly has an 'any' type error in typescript
- TS | Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Record<SecurityMode, boolean>'
- Element implicitly has an 'any' type because expression of type 'any' can't be used to index type
- TypeScript Err: "Element implicitly has an 'any' type because expression of type 'any' can't be used to index type
- Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Palette'
- How do I fix the error "Element implicitly has an 'any' type because the expression of type
- React Typescript: Element implicitly has an 'any' type because type has no index signature
- Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'typeof
- Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{...}'
- Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Breakpoints'
- how fix Element implicitly has an 'any' type because expression of type 'string' can't be used to index type?
- Global window object: Element implicitly has an 'any' type because index expression is not of type 'number'.ts
- React typescript error: Element implicitly has an 'any' type
- Typescript when I map imports it says 'Element implicitly has an 'any' type because expression of type 'string' to index type 'typeof import'
- Element implicitly has an 'any' type because expression of type 'any' can't be used to index type 'Item'
- Nested Object -> Element implicitly has an 'any' type because expression of type 'string' can't be used to index type
- Element implicitly has an 'any' type because expression of type 'string | number' can't be used to index type
- Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Number'
- Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'
More Query from same tag
- Sort an array based on string actual width in pixel
- Axios success/error calls with redux-promise
- how to prevent table from exceeding the viewport - react bootstrap
- React POST 422 (Unprocessable Entity)
- How to load initial data in Flux, but only if a component needs it
- onChange function on created select component
- Styled components for nested html elements (React)
- Why is useEffect() being triggered before the component is rendered?
- VSCode auto import - how to force Material-UI full path import
- Switching image src with images from an array on an interval in React
- React.js: Convert this kind of array format to JSON
- Auto Import of React Components in Visual Studio Code
- How to frame a URL in parent component and pass it to child component using react?
- onHover effect on ReactMapGL not scaling properly
- "ReferenceError: document is not defined" when trying to test a create-react-app project
- Trouble passing React prop to DOM element
- React Native react-native-maps Mapview does not show up
- How do I test that a function is called within a method using jest+enzyme+react+typescript?
- Changing the document title in React?
- Rendering multiple charts with React
- Access a form control value from component
- How do you refer to the main "this" when inside a loop?
- mockRejectedValueOnce is not a function
- React onChange doesn't return updated value after updating the state
- Module not found: can't resolve 'moduleName' in react js
- react-carousel-slider doesn't rerender
- Add script tag to React component without using props or context in NextJS
- Typescript: Define if property should be included based on value of other property
- Typescript useState hook on an object does not save
- How to remove data:image/png;base64 in base64 before uploading to api server through axios post in ReactJs