ts-json-schema-generator
ts-json-schema-generator copied to clipboard
Support inferrable types
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.
I've created the PR #1407 to fix my issue
:rocket: Issue was released in v1.2.0-next.3 :rocket: