elm-ts-json icon indicating copy to clipboard operation
elm-ts-json copied to clipboard

Possible to define elm type and encoder & decoder from typescript?

Open beenotung opened this issue 3 years ago • 1 comments

Currently this library allow one to define typescript type and elm type and encoder & decoder from combinator (source code) written in elm.

Is there another way. That allow one to define elm type and encoder & decoder from typescript type (parse from source code) or combinator functions / ast written in typescript ?

beenotung avatar Mar 23 '21 11:03 beenotung

If I'm understanding what you're describing, having an equivalent of elm-ts-json but where you write an Encoder/Decoder in TypeScript and it syncs with Elm (something like https://github.com/gcanti/io-ts), it's unfortunately not possible.

One of the interesting differences between Elm and TypeScript is that in Elm, you have to "prove" everything to the compiler. But in TypeScript, you can give type information and tell the TypeScript compiler to "just trust me on this."

You could generate an Elm decoder or encoder from TypeScript types, but I've talked about the reasons why I think that approach is limiting and not ideal (just my personal opinion).

So one of the unique advantages of taking a Decoder or Encoder written in Elm and turning syncing it with types in TypeScript is you don't have to generate any TypeScript code, just TypeScript types.

dillonkearns avatar Mar 23 '21 23:03 dillonkearns