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

Add support for int unions

Open burzomir opened this issue 1 year ago • 0 comments

Currently I use

TsJson.Codec.stringUnion
        [ ( "0", Reliable )
        , ( "1", Lossy )
        , ( "-1", Unrecognized )
        ]

to encode data for a JS library. The resulting type is "0" | "1" | "-1" and I have to call parseInt on the JS side to prepare data for the library. It would be nice to simply write

TsJson.Codec.intUnion
        [ ( 0, Reliable )
        , ( 1, Lossy )
        , ( -1, Unrecognized )
        ]

to get 0 | 1 | -1 type and avoid extra conversion on the JS side.

burzomir avatar May 10 '23 08:05 burzomir