interface DataStructure {
name: string;
url: string;
date: string;
popular: boolean;
}
const itemData: DataStructure = {
name: "Item 1",
url: "item-1",
date: "2012",
popular: true,
};
function getItemByURL(keys: Array<keyof DataStructure>) {
const itemsList = <DataStructure>{};
// Ensure only the necessary data is shown
keys.forEach((key) => {
if (key === "popular") {
itemsList[key] = itemData.popular;
}
if (typeof itemData[key] !== "undefined") {
itemsList[key] = itemData[key];
}
});
return itemsList;
}
I am encountering an issue with "itemsList[key]". I have tried solutions from similar problems, but none have worked for me. Can someone point out what I am missing here? Error: Type 'string | boolean' is not assignable to type 'never'. Type 'string' is not assignable to type 'never'