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
Item 26: Use Functional Constructs and Libraries to Help Types Flow
Things to Remember
Use built-in functional constructs and those in utility libraries like Lodash instead of hand-rolled constructs to improve type flow, increase legibility, and reduce the need for explicit type annotations.
constrowsImperative=rawRows.slice(1).map(rowStr=>{constrow={};rowStr.split(',').forEach((val,j)=>{row[headers[j]]=val;// ~~~~~~~~~~~~ No index signature with a parameter of// type 'string' was found on type '{}'});returnrow;});constrowsFunctional=rawRows.slice(1).map((rowStr)=>rowStr.split(",").reduce((row,val,i)=>((row[headers[i]]=val),row),// ~~~~~~~~~~~~~~~ No index signature with a parameter of// type 'string' was found on type '{}'{}));
letallPlayers=[];// ~~~~~~~~~~ Variable 'allPlayers' implicitly has type 'any[]'// in some locations where its type cannot be determinedfor(constplayersofObject.values(rosters)){allPlayers=allPlayers.concat(players);// ~~~~~~~~~~ Variable 'allPlayers' implicitly has an 'any[]' type}