As a Java developer diving into TypeScript for frontend development, I've encountered a simple JavaScript code snippet that I'd like to convert to TypeScript.
The original JavaScript code is:
let numbers = [123, 234, 345, 456, 567];
let names = ['Alex', 'Bree', 'Cara', 'Cole', 'Devon', 'Riley'];
let bigA = numbers.filter(function(item)) {
return item > 300;
}
Now, here's the modified TypeScript version:
let numbers: number[] = [123, 234, 345, 456, 567];
let names: string[] = ['Alex', 'Bree', 'Cara', 'Cole', 'Devon', 'Riley'];
let big: number[] = numbers.filter(function(item)) {
return item > 300;
}
However, an error regarding 'item' pops up: "Binding element 'item' implicitly has an 'any' type.ts(7031)", and I'm struggling to resolve it by simply adding return item: number > 300;
.
I prefer not using the alternative syntax of
let big: number[] = numbers.filter((item) => item > 300);
If you have any insights on how to tackle this issue, I would greatly appreciate it. Thank you!