How to provide a type definition when pushing elements into an array using TypeScript?
<p>I need to avoid using 'any' as a type definition when pushing elements into an array. I tried providing the type but I got an error. Here is sample code: </p>
<pre class="brush:php;toolbar:false;">interface answerProps {
state: string;
answer: string;
}
const results: Array<string> = [];
!isEmpty(answers) &&
answers.map((item: any) => results.push(`${item.state} : ${item.answer}`));</pre>
<p>Based on the above code, I want to avoid using a while loop to map array elements. </p>