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

Add an option to use 'brand type' on value classes and primitives #7

Closed
aSemy opened this issue Mar 3, 2022 · 1 comment
Closed
Labels
enhancement New feature or request

Comments

@aSemy
Copy link
Contributor

aSemy commented Mar 3, 2022

To help emulate Kotlin's strong typing, use 'brand typing' to specify primitives and value classes. Otherwise TypeScript doesn't discriminate between UInt and Long

Builtin primitives should be handled

type Byte = number & { __kotlin_byte__ : void};

Value classes too

package my.package

@Serializable
@JvmInline
value class UserCount(private val count: UInt)

Something like this...

type UInt = number & { __kotlin_uint__ : void};

type UserCount = UInt & { __my_package__usercount__ : void};
aSemy added a commit that referenced this issue Mar 4, 2022
- #2 Basic maps implementation
- #7 quick implementation of brand typing for value classes
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
@aSemy aSemy added the enhancement New feature or request label Apr 9, 2022
@aSemy
Copy link
Contributor Author

aSemy commented Apr 9, 2022

This has been implemented https://github.com/adamko-dev/kotlinx-serialization-typescript-generator/blob/v0.0.5/docs/value-classes.md#brand-typing, but I haven't used it much so I don't know how useful or accurate it is.

If it needs further work, make a new issue

TODO add it to the README #19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant