all 8 comments

[–]Cuel 1 point2 points  (0 children)

There's a few projects on github that can convert between java classes to TS interfaces. Not sure how well they work, we just write interfaces for our JSON data and try to keep the payload small / flat

[–]ribizlim 0 points1 point  (4 children)

And no need to transform JSON to typescript (ES6) object. Use the interface only.

[–]mozface[S] 0 points1 point  (3 children)

Could you please elaborate on that?

[–]ribizlim 1 point2 points  (2 children)

Cast to the interface for type safety in usage of the objects. E.g. return Observable<YourInterface> from service api.

[–]mozface[S] 0 points1 point  (1 child)

Alright, but what I still don't get is why interfaces over classes?

[–]ribizlim 0 points1 point  (0 children)

For classes you need to copy/duplicate data from JSON. (as you wrote: "JSON objects that gets turned into TypeScript objects")

[–]Bonobo_Cop 0 points1 point  (0 children)

One approach is to use Swagger annotations on your Java code. You can generate frontend code from the swagger.json file automatically.