Comments (3)
The problem is that TypeScript unions and sealed class don't map as much as I'd like.
The most striking difference is that sealed class are abstract classes, whereas named unions are not, and therefore they need to be omitted in the extends
clause.
Also, sealed children may be defined either as a nested classes or separate classes in the same file (since Kotlin 1.1). Unfortunately there is no way to query sealed children in the later case.
from ts-generator.
OK, so, check my PR - turns out sealed classes are more complicated than I initially thought. It also generates code (in a separate output property) to check if a JS object has a matching type; when working with union types this seemed necessary to implement. I did have to refactor the class visitor pattern a bit to make this work.
It may be more than you're looking for, and I haven't included unit tests, but it seems to work well on our Kotlin class model. I can add in some UTs if that helps.
It's true that there's no way using vanilla Kotlin or Java reflection to scan for subclasses. So I used the Reflections library to scan for subclasses; Reflections does some basic classpath scanning to accomplish this.
I'm also working on a gradle plugin to generate this on the fly for mixed-sourceset Kotlin and Node projects and/or multimodule projects.
from ts-generator.
I've added in UTs for two basic typedef cases. I had to refactor the factory code that builds TypeScriptDefinitions since the union type made it much more complex.
The actual generated code that does type checking still needs UTs.
from ts-generator.
Related Issues (20)
- Compile from Kotlin to JS with type definitions HOT 3
- Support for functions
- Enums as enums HOT 1
- Nullable type from mappings HOT 3
- Output properties in declaration order HOT 1
- Add support for readonly typescript types
- exception when running from java
- Kotlin Maps with non-string non-numeric keys should map to Map instead of an Object
- Kotlin Map with enum key should use [item in Enum] instead of [item: Enum]
- Is this project maintained? HOT 10
- String Enums
- Feature Request: ability to annotate integer fields HOT 1
- Sharing constants HOT 1
- Generated typescript doesn't use '?' for null types HOT 2
- How do we prevent computed properties from being generated HOT 1
- Propose an option to generate Optionals Instead of Nullables HOT 3
- tag version 1.1.2 HOT 1
- Field ordering
- Gradle plugin HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ts-generator.