You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, I'd like to thank you for the amazing work behind this tool!
It's a fantastic tool that saves us a lot of time, while ensuring that types are respected on the client side.
Context
I'm currently using TypeScript Generator to generate TypeScript declarations for a large hierarchy of Java classes.
These classes have several levels of depth and are serialized/deserialized using Jackson.
I use the @JsonTypeInfo annotation on the root class and the @JsonSubTypes annotation at each depth level.
This way serialization/deserialization works and TypeScript Generator generates tagged unions which I need to properly type these classes. 👌
Actual behavior
The only issue is that classes referencing intermediate subtypes (classes referencing other subtypes) seem to generate incorrect tagged unions.
Indeed, tagged unions always seem to reference interface declarations and not the tagged unions of the subtypes (when they exist).
Expected behavior
I would expect the tagged unions to reference the tagged unions of the subtypes (when they exist).
Type '{ type: "Cat"; name: string; age: number; numberOfLegs: number; breed: string; favoriteMeal: string; children: never[]; }' is not assignable to type 'AnimalUnion'.
Object literal may only specify known properties, and 'breed' does not exist in type 'Mammal'.(2322)
For this reason, I would expected the generated tagged unions to look like this:
Hi there,
First of all, I'd like to thank you for the amazing work behind this tool!
It's a fantastic tool that saves us a lot of time, while ensuring that types are respected on the client side.
Context
I'm currently using TypeScript Generator to generate TypeScript declarations for a large hierarchy of Java classes.
These classes have several levels of depth and are serialized/deserialized using Jackson.
I use the
@JsonTypeInfo
annotation on the root class and the@JsonSubTypes
annotation at each depth level.This way serialization/deserialization works and TypeScript Generator generates tagged unions which I need to properly type these classes. 👌
Actual behavior
The only issue is that classes referencing intermediate subtypes (classes referencing other subtypes) seem to generate incorrect tagged unions.
Indeed, tagged unions always seem to reference interface declarations and not the tagged unions of the subtypes (when they exist).
Expected behavior
I would expect the tagged unions to reference the tagged unions of the subtypes (when they exist).
Steps to reproduce
I created a small project to demonstrate the issue: typescript-generator-nested-subtypes.
The project is composed of the following classes:
@JsonTypeInfo
,@JsonSubTypes
@JsonSubTypes
@JsonSubTypes
The generated TypeScript declaration file is available here and looks like this:
This means I cannot write something like this:
Indeed, this generates a TypeScript error:
For this reason, I would expected the generated tagged unions to look like this:
Don't hesitate to tell me if I missed something.
Cheers!
The text was updated successfully, but these errors were encountered: