0

Currently, I'm querying a media through an API. It returns something like this:

{
  media_id: 42,
  media_type: 1,
  ...
}

where media_type can only be 1 (image), 2 (video), 3 (audio).

I'm declaring the Media interface as

export interface Media {
  media_id: number;
  media_type: number; // (1: Video; 2: Audio; 3: Image)
  ...
}

which doesn't seem to be a good idea since media_type requires the coders to read the doc and remember which number corresponds to which type.

What is the proper type to use with this? I'm thinking about enum but I can't think of the way to turn this into an enum.

Note: I'm pretty sure this must be a duplicate of a question. I've tried to search for it but I can't seem to find a good keywords to get the desired results. Sorry about that.

MongoLato
  • 351
  • 2
  • 20

0 Answers0