You are on page 1of 1

Hi I am getting some datatype error in typescript while getting first record of an array.

I am
initializing the data like -

const ABData= testData.B.map(({ id, name }) => ({


label: translateFn!(id),
value : name
}));

const newData: PropsInterface = {


displayData: ABData[0]
};
Below is my data -

export const testData: PropsInterface = {


A: [
{ value: "All", key: "All" },
],
B: [
{id: "0", name: ""},
{id: "100000008472", name: "Y6DC"}
],
C: "100000008472",
D: [{id: "0", name: "None"}],
E: [
{value: "", key: "None"},
{value: "A", key: "Test"},
]

}
Here is my interface -

export interface PropsInterface {


A: Array<First>;
B: Array<Second>;
C: string;
D: Array<Second>;
E: Array<First>;
}

export interface First{


key: string;
value: string;
}

export interface Second{


id: string;
name: string;
}
I am getting error in displayData if I am trying to get first data using 0th index.

error is - Type '{ label: string; value: string; }' is missing the following properties
from type 'Second[]': length, pop, push, concat, and 26 more.

You might also like