Skip to content

Suggestion: optional keyword to complement required #1112

Open
@Altreus

Description

@Altreus

I don't write objects with optional properties most of the time. I tend to prefer to use polymorphism to allow one of several data structures. When I do have an optional field, it's often something like "comments" or "extra info", and even then I don't have any philosophical objection to simply making it required but allowing it to contain the empty string.

An optional keyword to complement required would greatly benefit me (and hopefully others), without treading on the toes of people who are writing schemata with many optional values.

My proposition is thus:

  • Either required or optional may be provided
  • It is an error to provide both
  • The default remains as it is (everything optional), which is the same as providing required with an empty array
  • If optional is provided, anything not mentioned is now required
  • Passing an empty array to optional means everything is required

Hope that's both clear and a useful idea.

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalInitial discussion of a new idea. A project will be created once a proposal document is created.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions