Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JoshuaKGoldberg opened this issue Jul 29, 2022 · 0 comments
Open

Comments

@JoshuaKGoldberg
Copy link
Contributor

JoshuaKGoldberg commented Jul 29, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants