interface userDetails{
name:string;
age:number;
}
interface json{
name:string;
age:number;
address:string
}
export function createListItems<K,l>(jsonData:K[]): l[]{
let items: l[] = [];
type P=keyof l;
for(let i=0; i<jsonData.length; i++){
let obj:Partial<Record<P,l[P]>>={};
...I want to fetch only l properties(name,age) from k(name,age,addrees) and store it in obj. how can I do that.
}
.
items.push(obj as l);
return items;
}
createListItems<json,userDetails>({[name:"sunny",age:20,address:"pune"],[name:"minnu",age:20,address:"pune"]});
I want to fetch useDetails interface properties from json interface and push it to array. How to do that with generic approach. Something like
let obj:Partial<Record<keyof l,string|boolean>={}
At the end obj need to have name and age properties fetched from json interface.