You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When there is referenced schema that contains properties that contains property defined in the definitions, the property type is being resolved to undefined.
Example:
importtype{FromSchema,JSONSchema}from'json-schema-to-ts';constFooSchema={$schema: 'http://json-schema.org/draft-07/schema',type: 'object',properties: {bar: {$ref: 'https://example.com/bar.json',},},}asconstsatisfiesJSONSchema;constBarSchema={$schema: 'http://json-schema.org/draft-07/schema',$id: 'https://example.com/bar.json',type: 'object',definitions: {name: {type: 'string',},},properties: {name: {$ref: '#/definitions/name',},age: {type: 'number',},},}asconstsatisfiesJSONSchema;typeFooType=FromSchema<typeofFooSchema,{references: [typeofBarSchema]}>;// Result: type FooType = {// [x: string]: unknown;// bar?: {// [x: string]: unknown;// name?: undefined;// age?: number | undefined;// } | undefined;// }constfoo: FooType={bar: {name: 'Antonio',// Error: Type 'string' is not assignable to type 'undefined'age: 42,},};
In the README there is the line under the Definitions section that states ☝️ Wether in definitions or references, FromSchema will not work on recursive schemas for now. (link)
If this is not supposed to be supported, is there another workaround that we can get the type even in some more manual way?
The text was updated successfully, but these errors were encountered:
When there is referenced schema that contains properties that contains property defined in the
definitions
, the property type is being resolved toundefined
.Example:
In the README there is the line under the
Definitions
section that states☝️ Wether in definitions or references,
FromSchemawill not work on recursive schemas for now.
(link)If this is not supposed to be supported, is there another workaround that we can get the type even in some more manual way?
The text was updated successfully, but these errors were encountered: