Skip to content

Description comments can't be placed on oneOf > const values #475

Open
@JoshuaKGoldberg

Description

@JoshuaKGoldberg

For simplicity's sake, I'd like to be able to declare a type that is a union of strings, not a const enum.

{
  "oneOf": [
    { "const": "a", "description": "First comment (a)." },
    { "const": "b", "description": "Second comment (b)." }
  ]
}
Quick Node script that compiles the schema...
var { compile } = require("json-schema-to-typescript");

var schema = {
  oneOf: [
    { const: "a", description: "First comment (a)." },
    { const: "b", description: "Second comment (b)." },
  ],
};

var pendingResult = compile(schema, "example", {
  additionalProperties: false,
  bannerComment: "",
  declareExternallyReferenced: true,
});

pendingResult.then((result) => console.log(result));

Actual

export type Example = "a" | "b";

Expected

export type Example =
  /**
   * First comment (a).
   */
  | "a"
  /**
   * Second comment (b).
   */
  | "b";

Is this a reasonable request?

The context, similar to #470, is typescript-eslint rule schemas such as https://typescript-eslint.io/rules/explicit-member-accessibility where we'd like to keep the description to a simple string union, but still document them.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions