B
B
beDenz2019-10-03 14:56:12
typescript
beDenz, 2019-10-03 14:56:12

Typescript, map() method, interfaces?

Hello.
Wrote an interface, initialized an array of objects using it. Now I'm trying to iterate it with the map() method. But I am getting an error

Property 'map' does not exist on type 'Itemp'.ts(2339)

apparently you need to register it in the interface, although I can be wrong of course.
I tried to find an answer on the net, but there are only examples on primitives, which did not help me much.
The code itself:
interface Itemp {
  [index: number]: { x: number; y: number };
}

const temp: Itemp = [{ x: 1, y: 2 }, { x: 3, y: 4 }, { x: 5, y: 6 }];

const temp2: any = temp.map((item: { x: number; y: number }) => item);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-10-03
@beDenz

interface ItempElement {
  x: number;
  y: number;
};

interface Itemp extends Array<ItempElement> {};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question