Skip to content

The generated OneOf type can cause issues for large files #1077

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

Closed
viccon opened this issue Apr 14, 2023 · 3 comments
Closed

The generated OneOf type can cause issues for large files #1077

viccon opened this issue Apr 14, 2023 · 3 comments
Labels
openapi-ts Relevant to the openapi-typescript library

Comments

@viccon
Copy link

viccon commented Apr 14, 2023

Description
I have a response where the generated types looks like this:

data: {
  [key: string]: { items: OneOf<[_TWELVE_DIFFERENT_TYPES_]> }
}

The typescript compiler errors at the usage of OneOf with the following error: Type instantiation is excessively deep and possibly infinite.

Would it be possible to detect where issues like this could occur and use unions instead?

So in my case it would be something like:

data: {
  [key: string]: { items: [Type1 | Type2 | Type3 ... | Type12] }
}
@wiktor-obrebski
Copy link

wiktor-obrebski commented Apr 18, 2023

I have same issue with 9 types in OneOf<...>. Clearly it something wrong with OneOf definition.
I using [email protected].
Edited: looks like there is already an issue with this problem: #1019

@drwpow drwpow added the openapi-ts Relevant to the openapi-typescript library label May 22, 2023
@drwpow
Copy link
Contributor

drwpow commented Jul 7, 2023

Yup see my comment on #1019 for more explanation (and #894 for even more explanation, if you’re willing). It’s not necessarily that OneOf<> is wrong; just that TypeScript doesn’t have a good built-in for XOR comparisons, which are essential parts of OpenAPI schemas. So we do the best we can given the tools we have.

However, I’m applying the fix suggested in #1019 by falling back to unions at a complexity of > 5 determined arbitrarily. Ideally, when the union is too complex, it will naturally act as an XOR without the helper type. But at simpler unions, the XOR is needed.

@drwpow
Copy link
Contributor

drwpow commented Jul 7, 2023

Please try the most recent release, and let me know if that fixes your issue!

@drwpow drwpow closed this as completed Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
openapi-ts Relevant to the openapi-typescript library
Projects
None yet
Development

No branches or pull requests

3 participants