Skip to content

Support propertyNames with enum #337

@ghost

Description

propertyNames is included in the "not expressible in TS" list, but at least for the case with enum instead of pattern, this is not true. Consider the following example:

{
  "type": "object",
  "title": "workingHours",
  "definitions": {
    "weekdays": {"type": "string", "enum": ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"]}
  },
  "additionalProperties": {"type": "number"},
  "propertyNames": {"$ref": "#/definitions/weekdays"}
}

could well be expressed in TS as

enum weekdays {
  monday = "monday",
  tuesday = "tuesday",
  wednesday = "wednesday",
  thursday = "thursday",
  friday = "friday",
  saturday = "saturday",
  sunday = "sunday"
}
type workingHours = {[k in weekdays]: number};

The example also shows what would be the purpose of this instead of specifying the properties literally: weekdays does not have to be repeated all the time when there are more types making use of its keys.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions