ts-json-schema-generator icon indicating copy to clipboard operation
ts-json-schema-generator copied to clipboard

Support for `Required<T>` typescript helper

Open kirit0s opened this issue 6 years ago • 1 comments

export type T = Required<{ a?: string }>;

Actual:

{
  "$ref": "#/definitions/T",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "T": {
      "additionalProperties": false,
      "properties": {
        "a": {
          "type": "string"
        }
      },
      "type": "object"
    }
  }
}

Expected:

{
  "$ref": "#/definitions/T",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "T": {
      "additionalProperties": false,
      "properties": {
        "a": {
          "type": "string"
        }
      },
      "required": ["a"],
      "type": "object"
    }
  }
}
/**
 * Make all properties in T required
 */
type Required<T> = {
    [P in keyof T]-?: T[P];
};

kirit0s avatar Aug 05 '19 17:08 kirit0s

Thank you for filing the issue. Yes, we have indeed not implemented support for the -?. Can you send a PR to implement it?

domoritz avatar Aug 05 '19 17:08 domoritz