Skip to content

use of StringEnum attribute with Decode.Auto and Extra.withCustom #203

@joprice

Description

@joprice

When decoding a union annotated with StringEnum with Decode.Auto.generateDecoder, the generated decoder is simply parsing a string, so it does not fail on unknown enum cases.

Trying to work around this by passing a custom encoder to the extra parameter inadvertently overrides the decoding of all string types, since typeof<X>.FullName for a type with StringEnum is System.String. I have had similar problems with Erase unions, but unsure why.

Although I could avoid StringEnum altogether in most cases, I have some js code I'm interoping with which uses physical equality checks, and currently enum classes create a new instance of the class per instance of the enum, so I'm looking for a way to have a typesafe string wrapper that can have a validating decoder/encoder.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions