I am a novice when it comes to TypeScript, and I have been encountering challenges applying my JavaScript skills. Specifically, could someone assist me in converting the JavaScript code provided below into TypeScript?
If direct conversion is not feasible, are there any TypeScript functions that can achieve the desired result (an array without duplicate values).
This snippet is a straightforward method of eliminating duplicates from an array, but it appears that TypeScript does not allow me to define an empty object... I'm unsure...
The expected output of the given code is: ['John', 'Paul', 'George', 'Ringo']
Thank you!
const names = ['John', 'Paul', 'George', 'Ringo', 'John'];
function removeDups(names) {
let unique = {};
names.forEach(function(i) {
if(!unique[i]) {
unique[i] = true;
}
});
return Object.keys(unique);
}
removeDups(names)