Home > Software design >  Typescript - Document what type options mean
Typescript - Document what type options mean

Time:07-25

I'm writing a wrapper for an API with typescript and some routes use a filter that uses numbers to represent different things:

0 = none, 1 = minimal, 2 = status

I would like to somehow document within typescript what 0, 1 and 2 represent but can't seem to find a way. I've tried this without luck

async getServerCount( filter?: 0|1|2 /* 0 = none, 1 = minimal, 2 = status*/)

CodePudding user response:

Use an enum

enum FilterType {
  NONE = 0,
  MINIMAL = 1,
  STATUS = 2
}
async getServerCount( filter?: FilterType );

and then to use it

getServerCount( FilterType.NONE );
  • Related