-
Notifications
You must be signed in to change notification settings - Fork 0
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
Allow sealed classes to reference external enums #68
Conversation
Coverage report
Show files with reduced coverage 🔻
Test suite run success32 tests passing in 4 suites. Report generated by 🧪jest coverage report action from e95199e |
Ok @sam-bunger if you look in TaggedUnionGenerator, you'll see a few interesting lines:
Now, the compiler assumes that you're building your tagged unions off string unions, and hadn't considered that you would already have an enum ready to use instead. What you'll want to do is add some conditional logic around those lines (or inside https://github.com/asarazan/martok/blob/main/src/martok/declarations/TaggedUnionGenerator.ts#L108) which detects when the tag candidate is of enum type, and uses that instead. Unfortunately you'll also then need to override the naming scheme that the compiler uses ( I've got a decent amount of free time tomorrow so hmu and I can walk you through it. |
Also if you debug |
Codecov ReportBase: 95.06% // Head: 95.03% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #68 +/- ##
==========================================
- Coverage 95.06% 95.03% -0.03%
==========================================
Files 28 28
Lines 1073 1087 +14
Branches 250 259 +9
==========================================
+ Hits 1020 1033 +13
- Misses 50 51 +1
Partials 3 3
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
@asarazan Just added in an extra test, and added a new |
Not sure if a PR is a place to request this... BUT there is a feature that would really help Faceoff resolve some duplicate type issues.
Fixes #67
Resolves FACE-1206
The Problem
When Martok transpiles tagged union types, a new enum always gets created inside the generated sealed class, even if we want the tagged union type to reference an enum outside of the sealed class.
For example, our
GameSession
type is tagged using thisGameType
enum:When this transpiles we get two enum types, one outside the sealed class, and one inside the sealed class:
This makes it difficult because if we want multiple classes to reference the same enum then we'll need to manually delete the enum inside each sealed class.
The Solution
I really don't know! BUT I added in some tests in this PR that test against this use case