ThomasAribart / json-schema-to-ts

Infer TS types from JSON schemas 📝
MIT License
1.43k stars 30 forks source link

BUG: Non recursive schema resolves as "any" and fails the build #146

Closed mrded closed 1 year ago

mrded commented 1 year ago

I'm trying to turn into types a very basic schema:

const responseSchema = {
  type: 'object',
  additionalProperties: false,
  properties: {
    success: { type: 'boolean' },
    statusCode: { type: 'number' },
    message: { type: 'string' }
  },
  required: ['success', 'statusCode', 'message']
} as const;

type Response = FromSchema<typeof responseSchema>;

Which resolves as any.

When I try to build it, it fails with TS2589: Type instantiation is excessively deep and possibly infinite. error.

image

mrded commented 1 year ago

FYI: rolling back to v2.8 fixes the issue.

ThomasAribart commented 1 year ago

@mrded Yes it's a known issue, will be working on this tomorrow. Closing this as it's a duplicate of https://github.com/ThomasAribart/json-schema-to-ts/issues/144