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

Support inferrable types #1406

Closed
swnf opened this issue Sep 14, 2022 · 2 comments · Fixed by #1407
Closed

Support inferrable types #1406

swnf opened this issue Sep 14, 2022 · 2 comments · Fixed by #1407

Comments

@swnf
Copy link
Contributor

swnf commented Sep 14, 2022

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
Copy link
Contributor Author

swnf commented Sep 15, 2022

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

@github-actions
Copy link

github-actions bot commented Dec 3, 2022

🚀 Issue was released in v1.2.0-next.3 🚀

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

Successfully merging a pull request may close this issue.

2 participants