Z
Z
zlodiak2019-10-29 21:32:04
Angular
zlodiak, 2019-10-29 21:32:04

How to write a nested type?

There is a subscription to the stream. It receives data in the following format:

{
  data: [
    {id: 1, score: 11},
    {id: 2, score: 22},
    {id: 3, score: 33},
  ]
}

Please help me to set the accepted type in the subscribe block. Here is my attempt:
export interface IScore {
  id: number;
  score: number;
}

flow$.subscribe(res: {data: IScore[]} => {
  console.log(res);
});

The important thing is that I would not like to edit the interface IScore because it is already used in a lot of places. I would like to prescribe the type in the subscribe block

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stockholm Syndrome, 2019-10-29
@StockholmSyndrome

flow$.subscribe((res: {data: IScore[]}) => {
  console.log(res);
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question