In my code, I have created a function to fetch objects from my dummy data and assign them to a variable.
setData(key: string) {
let dataChunk: ProductIndex = PRODUCTDATA.filter(a => {a.productId == key;});
this.ProductData = dataChunk;
}
The issue I am facing is the TS2739 error at line 15,13 where dataChunk
is declared. It states that each property in the type ProductIndex
is missing from the type ProductIndex[]
, which is the type of PRODUCTDATA
.
This is how my data is structured:
export const PRODUCTDATA: ProductIndex[] = [
{
productId: 'divider_01',
title: 'Divider 01',
description: 'A brief description for Divider 01',
sizes: [...],
instructionKey: 'divider_01_instruction_key'
},
{...},
{...}
]
The ProductIndex
interface is defined as follows:
export interface ProductIdCore { productId : string; }
export interface TitleCore { title : string; }
export interface ShortDescriptionCore { description : string; }
export interface ProductIndex extends ProductIdCore, TitleCore, ShortDescriptionCore{
sizes: ProductIndexItem[];
instructionKey: string;
}
I am using Angular 8 with TypeScript 3.4.0 and I am having trouble understanding what mistake I am making. Any help would be greatly appreciated.