I am getting error in this implementation of typescript code. I am mapping here one type to another. But vscode shows error that variable 'test' is used before being assigned. can anyone please help?
interface A {
name: string;
age: string;
sex: string;
}
interface B {
name: any;
age: string;
sex: string;
}
const modifyData = (g : B) :A => {
let test: A;
test.name = g.name['ru'];
test.age = g.age;
test.sex = g.sex;
return test as A;
};
const g = [{
"name": {
"en": "George",
"ru": "Gregor"
},
"age": "21",
"sex": "Male"
},
{
"name": {
"en": "David",
"ru": "Diva"
},,
"age": "31",
"sex": "Male"
}];
const data = g.map(modifyData);
console.log(data);