Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--expose all breaks generation with generic types. #2002

Closed
kelleyk opened this issue Jun 27, 2024 · 4 comments · Fixed by #2009
Closed

--expose all breaks generation with generic types. #2002

kelleyk opened this issue Jun 27, 2024 · 4 comments · Fixed by #2009

Comments

@kelleyk
Copy link

kelleyk commented Jun 27, 2024

I'm using the latest release (v2.3.0) of ts-json-schema-generator.

While trying to get it running on my project, I ran into the following somewhat opaque error:

/path/to/project/node_modules/ts-json-schema-generator/dist/ts-json-schema-generator.js:74
    throw error;
    ^

TypeError: Cannot read properties of undefined (reading 'getId')
    at new UnknownTypeError (/path/to/project/node_modules/ts-json-schema-generator/dist/src/Error/Errors.js:24:48)
    at ChainTypeFormatter.getTypeFormatter (/path/to/project/node_modules/ts-json-schema-generator/dist/src/ChainTypeFormatter.js:29:15)
    at ChainTypeFormatter.getChildren (/path/to/project/node_modules/ts-json-schema-generator/dist/src/ChainTypeFormatter.js:21:21)
    at CircularReferenceTypeFormatter.getChildren (/path/to/project/node_modules/ts-json-schema-generator/dist/src/CircularReferenceTypeFormatter.js:30:50)
    at /path/to/project/node_modules/ts-json-schema-generator/dist/src/TypeFormatter/ObjectTypeFormatter.js:43:59
    at Array.reduce (<anonymous>)
    at ObjectTypeFormatter.getChildren (/path/to/project/node_modules/ts-json-schema-generator/dist/src/TypeFormatter/ObjectTypeFormatter.js:38:44)
    at ChainTypeFormatter.getChildren (/path/to/project/node_modules/ts-json-schema-generator/dist/src/ChainTypeFormatter.js:21:44)
    at CircularReferenceTypeFormatter.getChildren (/path/to/project/node_modules/ts-json-schema-generator/dist/src/CircularReferenceTypeFormatter.js:30:50)
    at DefinitionTypeFormatter.getChildren (/path/to/project/node_modules/ts-json-schema-generator/dist/src/TypeFormatter/DefinitionTypeFormatter.js:21:84)

Using the generic-simple test input, I think that I've narrowed down the things that trigger the error. In particular, the generator runs without error when the input does not contain generic TypeScript types and the --expose all command-line parameter is present, or vice versa; but that error is thrown when both are present.

I couldn't find any other issues that seem similar.

@arthurfiorette
Copy link
Collaborator

Hey @kelleyk, could you create a minimum reproducible example so that we can debug?

@kelleyk
Copy link
Author

kelleyk commented Jun 29, 2024

Sure; sorry if I wasn't clear enough: I think that the generic-simple test input that is in this repository is a pretty decent "minimal repro".

It contains the following TypeScript type definintions:

export interface MyGeneric<T> {
    field: T;
}

export interface MyObject {
    value: MyGeneric<number>;
}

This, without --expose all, works fine.

$ npx ts-json-schema-generator --path ~/src/github.com/vega/ts-json-schema-generator/test/valid-data/generic-simple/main.ts --out /tmp/foo.json

When I add --expose all, however, I get the error that I mentioned above.

$ npx ts-json-schema-generator --path ~/src/github.com/vega/ts-json-schema-generator/test/valid-data/generic-simple/main.ts --out /tmp/foo.json --expose all
/Users/kelleyk/.npm/_npx/dec19a6f9609cbed/node_modules/ts-json-schema-generator/dist/ts-json-schema-generator.js:74
    throw error;
    ^

TypeError: Cannot read properties of undefined (reading 'getId')
    at new UnknownTypeError (/Users/kelleyk/.npm/_npx/dec19a6f9609cbed/node_modules/ts-json-schema-generator/dist/src/Error/Errors.js:24:48)
    at ChainTypeFormatter.getTypeFormatter (/Users/kelleyk/.npm/_npx/dec19a6f9609cbed/node_modules/ts-json-schema-generator/dist/src/ChainTypeFormatter.js:29:15)
    at ChainTypeFormatter.getChildren (/Users/kelleyk/.npm/_npx/dec19a6f9609cbed/node_modules/ts-json-schema-generator/dist/src/ChainTypeFormatter.js:21:21)
    at CircularReferenceTypeFormatter.getChildren (/Users/kelleyk/.npm/_npx/dec19a6f9609cbed/node_modules/ts-json-schema-generator/dist/src/CircularReferenceTypeFormatter.js:30:50)
    at /Users/kelleyk/.npm/_npx/dec19a6f9609cbed/node_modules/ts-json-schema-generator/dist/src/TypeFormatter/ObjectTypeFormatter.js:43:59
    at Array.reduce (<anonymous>)
    at ObjectTypeFormatter.getChildren (/Users/kelleyk/.npm/_npx/dec19a6f9609cbed/node_modules/ts-json-schema-generator/dist/src/TypeFormatter/ObjectTypeFormatter.js:38:44)
    at ChainTypeFormatter.getChildren (/Users/kelleyk/.npm/_npx/dec19a6f9609cbed/node_modules/ts-json-schema-generator/dist/src/ChainTypeFormatter.js:21:44)
    at CircularReferenceTypeFormatter.getChildren (/Users/kelleyk/.npm/_npx/dec19a6f9609cbed/node_modules/ts-json-schema-generator/dist/src/CircularReferenceTypeFormatter.js:30:50)
    at DefinitionTypeFormatter.getChildren (/Users/kelleyk/.npm/_npx/dec19a6f9609cbed/node_modules/ts-json-schema-generator/dist/src/TypeFormatter/DefinitionTypeFormatter.js:21:84)

Let me know if there's anything else you need!

@arthurfiorette arthurfiorette changed the title ts-json-schema-generator throws an error when generics are used in combination with --expose all --expose all breaks generation with generic types. Jul 1, 2024
@arthurfiorette arthurfiorette linked a pull request Jul 1, 2024 that will close this issue
@arthurfiorette
Copy link
Collaborator

hey @kelleyk can you try with @2.3.1--canary.2009.14b4e3c.0 and see if it was fixed?

Copy link

github-actions bot commented Jul 3, 2024

🚀 Issue was released in v2.4.0-next.0 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants