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

Generate enums closed-polymorphic classes, and use literal enum members as the discriminator #10

Closed
aSemy opened this issue Mar 4, 2022 · 0 comments · Fixed by #8
Closed

Comments

@aSemy
Copy link
Contributor

aSemy commented Mar 4, 2022

I want to be able to use literal enum members to discriminate classes

https://www.typescriptlang.org/docs/handbook/enums.html#union-enums-and-enum-member-types

@Serializable
sealed class Project {
  abstract val name: String
}

@Serializable
class OwnedProject(override val name: String, val owner: String) : Project()

@Serializable
class DeprecatedProject(override val name: String, val reason: String) : Project()

fun main() {
  val tsGenerator = KxsTsGenerator()
  println(tsGenerator.generate(OwnedProject.serializer().descriptor))
}

should generate something like

enum ProjectKind {
  OwnedProject,
  DeprecatedProject,
}

interface Project {
  type: ProjectKind;
}

interface OwnedProject {
  type: ProjectKind.OwnedProject;
  name: string;
  owner: string;
}

interface DeprecatedProject {
  type: ProjectKind.DeprecatedProject;
  name: string;
  reason: string;
}
aSemy added a commit that referenced this issue Mar 4, 2022
- add TOC to all docs
- Map generation for complex and enum keys #2 #3
- update test template, for easier comparison after failures
- tests for #10
@aSemy aSemy linked a pull request Apr 3, 2022 that will close this issue
@aSemy aSemy closed this as completed Apr 3, 2022
aSemy added a commit that referenced this issue Apr 3, 2022
* - #1 basic lists implementation
- #2 Basic maps implementation
- #7 quick implementation of brand typing for value classes

* map tests #2 #3

* generate implementations and test improvements

- add TOC to all docs
- Map generation for complex and enum keys #2 #3
- update test template, for easier comparison after failures
- tests for #10

* suppress warning in tests

* `export enum` -> valid for .d.ts files

* test for ignoring fields with @transient, and if an interface has no properties, don't have a blank line between {}

* test for objects, and fix test expectations in polymophic classes, so they extend parent interfaces

* try fixing knit gradle task warning

* - replace jacoco with kotlinx.kover
- clean up root build.gradle.kts
- change package name of example code (so the coverage report can be package filtered, if needed)
- create a kotlin.multiplatform convention plugin

* bump gradle version

* set max line length to 100

* mucking about with plugins and compilation processors

* tidy up gradle config

* refactor kxs generator

* update tests, and add some more

* major refactor to get things more like a library, and steps towards handing open/closed polymorphism

* sealed classes working!

- 'export' all TS Declarations
- ignore blank lines in knit tests
-

* some Sealed interfaces and type ref improvements

* temp fix for open poly classes

* normalize knit code comparisons

* update tests after temp fix for open poly classes

* update sealed poly tests

* rm migrated code

* rm unneeded TsTypeRef.Unknown

* rename TsType to TsTypeAlias, and update docs in tsElements.kt

* code cleanup, documentation

* docs, more Maps tests/examples/workarounds

* update gitattributes

* rename 'knit' subproject to 'code'

* prep for jitpack

* docs update

* improve recursive descriptor extraction

* version bum git-versioning plugin

* better helper function for mutable maps with default puts

* simplify the API

* code tidup

* formatting, code tidying

* kmm gradle config tidy up

* bump gradle version

* add jitpack button

* fix maven publishing

* update project name & group

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

Successfully merging a pull request may close this issue.

1 participant