1

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?

2
  • yes it will be because in this case { key:any } any will be treated as alias of key. use it something like this { key }: { key: any } Commented Nov 7, 2019 at 9:42
  • `arrayData.map(({ key, value }: any) => { console.log("***", key, value); }); Commented Nov 7, 2019 at 9:45

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

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

output : [10, "test", true]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.