-
Notifications
You must be signed in to change notification settings - Fork 17
[improvement] Generate more lenient enums #170
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
Conversation
Generate changelog in
|
Lets try out the code change in a large internal repo and then we should be good to go |
I tested this on one of our conjure generated packages that has a bunch of enums, and it all seems to work. |
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 to me
This change breaks the generated code for empty enums. Before this change
generated
and after this change it generates
which fails to compile with the error
|
thanks for spotting @tjwilson90 . I think we can generate this instead for empty enums:
I can put up a fix first thing tomorrow morning if you think that works, but I'm also happy to revert in the meantime. |
Also, I'm curious - do you actually use empty enums in your typescript code, or was this an API in progress? |
@patrickszmucer is |
My conjure api has a lot of redundancy / self similarity and is itself generated (you can imagine Aircraft being one of many different types of objects). I generate a similar search api for all of them. Some of those generated types (like aircraft) don't have any geo point fields, so the corresponding enum is empty. |
I don't mind waiting until tomorrow. It blocks an autobump which isn't high priority. |
@ferozco you're right - seems like However, I think I found a better solution - we can use |
Fix here #176 |
Fixes #80
Based on #85 (which ended up being reverted) but I used namespaces instead of objects in order to preserve back compatibility.
Before this PR
We generated TypeScript enums which were difficult to use across library boundaries since equivalent enums could no be assigned to each other. See #80 for more details
After this PR
We generate a union type and a namespace.
Notes
I tested the edge case in #85 (comment) which caused the original attempt to be reverted and this time everything compiles correctly:
https://www.typescriptlang.org/play?#code/PTAEHkBsBNQYwPbQKYHNkDsCwAoZAPABwQCcAXeBDAZwswFcBbCAGQBEB9AUQDkBVALKgA3rlDjQAMXDhQAXlAAiaeEUAaMRIBCAQQBK8pbr3rN43QC1Diy6ZwBfXLhCgeyAO6UU6bHiKkKDABDRmRqQiC4ZFcuAHVufiFRHAlQAmJyUDIAT0JolWsVRQBuMzT-TJy80GNrYxKy9ICs3OjLOp0LBpxGiopEGgoChWUZbtSmzIHaGv0Ok1KUiUn+qhn2kdtFxz8MiironjiEwUMAa2RshAAzFrybmPjeQUXnMChYACNkAAsggDcAJYIegkXDXegYOBkYEYUDUeifajIMgcBAwAAUERIIQAXKxOM8BAA6AoAHwJJxJlgAlCIdhCoTCqKAUNcgvRIGQAApBHGMNGY-5BSD0aIKcDsKmkmR04Q7Nkcrm8-mC6AYyWExLE4w0144FxuTzfP5AkEkUAAWkojEIgMgYXBkOhsPhiORqIwHixfLxj2l5P9RJ1nTloB2bykQXt1CyCBtdodoEBGGFkEBsARSJRTqZrsY2UkzoAzD7+fiuPgyJhoNQADxHJ6JNRKa4IBCKAB8cojOCAA