How do I check if 'key' is correctly populated with 'known' values in JSON file

后端 未结 3 1955
Happy的楠姐
Happy的楠姐 2021-01-23 01:49

I am trying to check if a particular key is assigned with only a set of values. This values are listed as an enum in Typescript.

P

3条回答
  •  抹茶落季
    2021-01-23 02:19

    I achieved this with the following code:

    enum Regions {
    NA = "na",
    EMEA = "emea",
    APAC = "apac"
    }
    
    const possibleRegions = [Regions.NA, Regions.EMEA, Regions.APAC];
    
    private isValidRegion(value) 
    {
        return value !== null && value.Region !== null && possibleRegions.indexOf(value.Region) > -1;
    }
    

提交回复
热议问题