user10201522
user10201522

Reputation:

Use Typescript in ReactJs

I want to write this code: .map(({ key }) => key); using typescript, i did this: .map(({ key:any }) => key);, but i got an error: 'any' is declared but its value is never read.. How to apply typescript in my situation?

Upvotes: 1

Views: 94

Answers (2)

Muni Kumar Gundu
Muni Kumar Gundu

Reputation: 532

const array: any = [{ test: 10 }, { test: 'test' }, {test: true}];
console.log(array.map(({ test }: {test: any}) => test));

output : [10, "test", true]

Upvotes: 0

iamolegga
iamolegga

Reputation: 1025

What you do is destructing argument and assign property to new value, instead you should do this:

.map(({ key }: { key: any }) => key);

I would suggest to read more about TS in handbook

Upvotes: 2

Related Questions