Typescript Element implicitly has an 'any' type because expression of type 'number' can't be used to index
thx to reply bill.gates
(this.myobject as YourType)[i]._id;
This form works perfectly
Instead, I put any
in the type.
It functions as I want
(this.myobject as any)[i]._id;
Is there a problem if I put any
?
react typescript error - element implicitly has an any type because expression of type string cant be used to index type {}
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;
}, {});
Related Topics
Calculating Sum of Checked Checkboxes
How to Update Component State on Redux State Change
How to Autoplay a Music Using Audio Tag in Jquery
Weird Behaviour With on Click Event Binding; Event Not Firing
Document.Queryselector Always Returns Null
Bootstrap 4 Navbar-Toggler-Icon Does Not Appear
How to Tell If a Dom Element Is Visible in the Current Viewport
How to Remove Image from Browser Cache
Switch Fontawesome Icon on Click, Not Working
Parsing Error: Unexpected Token, Expected ","
How to Put a Variable in an Src Attribute
How to Wrap Each Word of an Element in a Span Tag
How to Pass Checkbox State to Onclick Function in React
How to Remove a Parameter from a Url
Generate and Download CSV File With PHP and Ajax