ThomasAribart / json-schema-to-ts

Infer TS types from JSON schemas 📝
MIT License
1.44k stars 31 forks source link

Issue when importing generated type into another module #87

Closed gurumaxi closed 2 years ago

gurumaxi commented 2 years ago

Generated types are not recognized when imported in other modules.

export const CarSchema = {
    type: 'object',
    properties: {
        color: {
            type: 'string',
        },
    },
    required: ['color'],
    additionalProperties: false,
} as const;

export type Car = FromSchema<typeof CarSchema>; will result in type Car = unknown in the imported module. If I specify a deserialize option, it transforms into any: type Car = any and the error Type instantiation is excessively deep and possibly infinite appears. I am aware of this FAQ, but since this CarSchema only has one string attribute, there should not be heavy computations ongoing. Is there maybe something I can do to resolve this issue?

gurumaxi commented 2 years ago

I am going to close this issue, as the problem wasn't actually a problem. I imported a generated type (module1) into module2. In module1, I used path aliases, which obviously cannot be resolved by module2. Therefore, the imported type always resolved to any in module2.