Hi, I've made a 'KSerializer to TypeScript generat...
# serialization
a
Hi, I've made a 'KSerializer to TypeScript generator'. It will take an
@Serializer
annotated class and generate some TypeScript interfaces - so they can generate compatible JSON. The basics are in, and it needs more work to finish up some of the tricky bits. Please take a look! https://github.com/adamko-dev/kotlinx-serialization-typescript-generator/ It's available from JitPack. There's code examples in the docs directory
👍 3
a
Looks slick! The open issues you have in there also cover the main things I could think of
🙏 1
The magic end-result here would be if — in addition to a
@TsExport
annotation — you could somehow annotate a class with
@TsWrap
and have KSP also generate a TS-friendly wrapper for that class that ◦ wraps the annotated original class into a `@JsExport`ed one ◦ creates methods on that wrapper with the same names as the original class, but method signatures modified to use your generated `external interface`s instead of the original Kotlin classes ◦ uses
kotlinx.serialization
to automatically map between
external interface
s and kotlin classes
a
Thanks! I'm not sure I understand your magic end result. What do you mean by a wrapped original class? I'm finding it difficult to think of a situation where creating that sort of automation would be less work than just creating a TypeScript class manually!
a
Ah I think I misread things — at first, I thought this library was generating Kotlin/JS `external interface`s, rather than directly generating TS definitions!