-
Notifications
You must be signed in to change notification settings - Fork 202
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
fix: Go back to generating enums out of unions containing enums #2149
Conversation
Happy to address feedback @domoritz :) |
Good points, should be addressed now @arthurfiorette! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Just one comment. Thanks for the pull request!
I fixed some linting issues and added a test case that also ensures some of my use cases. When enums are exported we cannot allow any merging of their actual types. |
@@ -43,8 +48,8 @@ export class LiteralUnionTypeFormatter implements SubTypeFormatter { | |||
}; | |||
} | |||
|
|||
const values = uniqueArray(types.map(getLiteralValue)); | |||
const typeNames = uniqueArray(types.map(getLiteralType)); | |||
const values = uniqueArray(types.flatMap(getLiteralValues)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can probably become map again if we fix the thing below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did it for us since i also need this PR :)
🚀 PR was released in |
Problem
feat: improve literal union type handling #1927 improved some cases of handling union types, but it broke one we rely heavily on at PostHog:
Before #1927 types such as
type X = Enum.A | Enum.B
were output"enum": ["a", "b"]
, since #1927 they are instead series ofanyOf
– whereastype X = "a" | "b"
continued to beenum
. This doesn't seem to have been covered by any test case.The
anyOf
output breaks our downstream processing of the schema, and just seems less practical thanenum
.Changes
This PR updates LiteralUnionTypeFormatter to support enums too – their underlying values are literal after all, and
ts-json-schema-generator
did make use of this before the regression.I committed so that it's easily immediately what the difference in union output is before (on
next)
vs. after (this branch).See here: a734160#diff-ba53f2224477f939f2a9762fe35a747aede17fd1e8caab8e4054b135857f2de9
Version
Published prerelease version:
v2.4.0-next.6
Changelog
🎉 This release contains work from new contributors! 🎉
Thanks for all your work!
❤️ Michael Matloka (@Twixes)
❤️ null@dcharbonnier
❤️ Werner Robitza (@slhck)
❤️ Bence Balogh (@baloghbence0915)
🚀 Enhancement
--expose all
with generic types #2009 (@arthurfiorette)🐛 Bug Fix
next
🔩 Dependency Updates
Authors: 7