Open alan-nf opened 2 years ago
Using v0.53.1:
export interface Toggleable { enabled: boolean; } export type ScrewsUpSchemaConfig = Toggleable & {}; export type DoesNotGetEnabledPropConfig = Toggleable & { response: string; }; export interface Config { screwsUpSchema?: ScrewsUpSchemaConfig; doesNotGetEnabled?: DoesNotGetEnabledPropConfig; }
typescript-json-schema --noExtraProps --strictNullChecks --required ./tsconfig.json Config > schema.json produces:
typescript-json-schema --noExtraProps --strictNullChecks --required ./tsconfig.json Config > schema.json
{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "definitions": { "Toggleable": { "additionalProperties": false, "properties": { "enabled": { "type": "boolean" } }, "required": [ "enabled" ], "type": "object" } }, "properties": { "doesNotGetEnabled": { "additionalProperties": false, "properties": { "response": { "type": "string" } }, "required": [ "response" ], "type": "object" }, "screwsUpSchema": { "$ref": "#/definitions/Toggleable" } }, "type": "object" }
Note that if I give ScrewsUpSchemaConfig any properties (instead of {}):
ScrewsUpSchemaConfig
{}
export type ScrewsUpSchemaConfig = Toggleable & { a: number };
Then doesNotGetEnabled DOES get the enabled property:
doesNotGetEnabled
enabled
{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "doesNotGetEnabled": { "additionalProperties": false, "properties": { "enabled": { "type": "boolean" }, "response": { "type": "string" } }, "required": [ "enabled", "response" ], "type": "object" }, "screwsUpSchema": { "additionalProperties": false, "properties": { "a": { "type": "number" }, "enabled": { "type": "boolean" } }, "required": [ "a", "enabled" ], "type": "object" } }, "type": "object" }
Note: another workaround is to convert doesNotGetEnabled to use an interface that extends Toggleable
Toggleable
Similar to https://github.com/YousefED/typescript-json-schema/issues/359 (in that they both deal with intersection types)
Using v0.53.1:
typescript-json-schema --noExtraProps --strictNullChecks --required ./tsconfig.json Config > schema.json
produces:Note that if I give
ScrewsUpSchemaConfig
any properties (instead of{}
):Then
doesNotGetEnabled
DOES get theenabled
property:Note: another workaround is to convert
doesNotGetEnabled
to use an interface that extendsToggleable
Similar to https://github.com/YousefED/typescript-json-schema/issues/359 (in that they both deal with intersection types)