I am seeing the TypeScript error 'Parameter 'row' implicitly has an 'any' type'
in my React datatable component, which occur when I declare this code in column selector, value row is highlighted with red.
Parameter 'row' implicitly has an 'any' type.
8 | {
9 | name: 'Year',
> 10 | selector: row => row.year,
| ^^^
11 | },
12 | ];
This is the code
const columns = [
{
name: 'Title',
selector: row => row.title,
},
{
name: 'Year',
selector: row => row.year,
},
];
I am a newbie in react. Any help will be appreciated 🙂
2
Answers
After searching about
implicity has an 'any' type
I got the answer and this is the example code.That's it, just put
row
inside parenthesis and add value ofany
. :)You’re not telling typescript where you’re going to be using columns so it implicitly things that
row
is anyYou could do something like this
It’s essentially a wrapper function for helping you type rows (you could also make it a prop so you can directly pass columns as a prop to the datatable)
Also if you don’t have an explicit type declaration for your row you can do
buildColumns<typeof rows[number]>
typeof row
-> gets the type of the arraytypeof row[number]
-> gets the type of a single element of the array