M
M
Maxim Ivanov2017-01-08 19:32:09
JavaScript
Maxim Ivanov, 2017-01-08 19:32:09

How to write an interface in TypeScript?

The server returns this JSON

{
  "globalOptionList": [
    {
      "value": "Максим Иванов",
      "text": "Выдан: 08.01.2017"
    },
    {
      "value": "Максим Иванов",
      "text": "Выдан: 06.01.2017"
    }
  ],
  "globalCountCertificate": 1,
  "error": false
}

I want to initialize a public variable in a class, but I don't quite understand how to describe such a structure in TS, help a beginner!
interface Response {
..
}

class App {
 
 public res: Response;

}

And how will interfaces help me when debugging or testing (I haven’t done this yet and I don’t know how to write component-testing on ts)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
_
_ _, 2017-01-08
@splincodewd

interface CertList {
  error?: boolean,
  globalCountCertificate?: number,
  globalOptionList: Array<{ value: string; text: string }>;
};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question