Skip to content

Imported types generate different schema than identical inline types #2233

@alexchexes

Description

@alexchexes

When a type is imported from another file - even a simple object type - the generated schema includes an extra $ref and definition, unlike the same type defined inline.

Reproduction

Repo: https://github.com/alexchexes/ts-jsg-import-vs-inline-repro

Compare:

Expected

Same schema structure for both files - flattened shape directly under MyObject.

Actual result

Schema for the import version uses a $ref to a separate definition, making the output structurally different.

Impact

While this is a minimal reproduction, in real-world projects the impact is significant.
For example, using almost any non-trivial utility type from type-fest (or manually crafted helpers like DeepPartial, Merge, etc.) results in a bloated schema with long, chained $refs and generic type names like:

"OverrideProperties<interface-13180666-71-18834-...,structure-13180666-0-32472[false,{}]>"

See example (src)

Even when the structure is identical, the generator produces separate definitions for each imported utility in the chain - making the schema harder to read, debug, compare, and test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions