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

Support inferrable types

Open swnf opened this issue 3 years ago • 1 comments

I have the following typescript code:

export class Foo {
  a: boolean = false;
  b = false;
}

ts-json-schema-generator generates the following schema:

{
  "$ref": "#/definitions/Foo",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "Foo": {
      "additionalProperties": false,
      "properties": {
        "a": {
          "type": "boolean"
        }
      },
      "required": [
        "a"
      ],
      "type": "object"
    }
  }
}

It seems like it just skips b because it has no explicit type. However, this is valid typescript. It is not even allowed to add types here if you use the recommended config of typescript-eslint. I don't think it's possible to get the type directly from the AST. Maybe it is possible to implement something similar to the eslint rule no-inferrable-types in this project.

swnf avatar Sep 14 '22 14:09 swnf

I've created the PR #1407 to fix my issue

swnf avatar Sep 15 '22 14:09 swnf

:rocket: Issue was released in v1.2.0-next.3 :rocket:

github-actions[bot] avatar Dec 03 '22 02:12 github-actions[bot]