typeshare icon indicating copy to clipboard operation
typeshare copied to clipboard

Elm support with json Decoders

Open kreibaum opened this issue 2 years ago • 4 comments

Would I be welcome to work on an Elm Language implementation for typeshare?

Elm is a small language, it has very strict type checking and I like using it together with a rust backend.

One peculiarity is, that you can't just tell Elm "here is some data, trust me it is a MyCustomType". Instead you need to also generate Encoders and Decoders that describe how the json is created / parsed.

Would that also be something you see in typeshare? So far I have just read through parts of the typescript language definition and looked at the Language type. Neither really has a section where I would put it. But it might make sense to put an encoder and a decoder right after each type.

Edit, to give some time information: I don't expect to work on this before new year (2023).

kreibaum avatar Nov 25 '22 19:11 kreibaum

As an example, here is a rust class

https://github.com/kreibaum/rust_elm_typegen/blob/main/src/tests/person.rs

And when translated to Elm you get

https://github.com/kreibaum/rust_elm_typegen/blob/main/src/tests/Person.elm

Note that in Rust, everything except for the person struct is just in there to test that the typegen utility doesn't just pick up everything.

kreibaum avatar Nov 25 '22 20:11 kreibaum

We would absolutely be open to adding support for Elm. Feel free to open a PR!

Would that also be something you see in typeshare? So far I have just read through parts of the typescript language definition and looked at the Language type. Neither really has a section where I would put it. But it might make sense to put an encoder and a decoder right after each type.

We do define custom encoders and decoders in some cases - take a look at our Swift implementation for an example of this: https://github.com/1Password/typeshare/blob/main/core/data/tests/can_generate_generic_struct/output.swift#L46.

snowsignal avatar Dec 01 '22 23:12 snowsignal

I should clarify that the low-priority tag means the Typeshare team won't be actively working on this issue, at least for the moment. But you are absolutely free to open a PR.

snowsignal avatar Feb 12 '23 02:02 snowsignal

That is precisely my expectation. But thanks for clarifying.

Feel free to also close this issue if you want to fight backlog growth and then I'll just open another one once I am actually working on something.

kreibaum avatar Feb 12 '23 08:02 kreibaum