Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decode into a union type? #33

Closed
ben-eb opened this issue Oct 8, 2020 · 1 comment
Closed

Decode into a union type? #33

ben-eb opened this issue Oct 8, 2020 · 1 comment

Comments

@ben-eb
Copy link

ben-eb commented Oct 8, 2020

Hello 馃憢

I'd like to use this library to decode some environment variables into a union type, something like this:

type SandboxEnviroment = {
  status: "sandbox";
  name: string;
}

type LiveEnvironment = {
  status: "live";
  name: string;
  credentials: string;
}

type Environment = SandboxEnviroment | LiveEnvironment

If I have IS_SANDBOX set to true in my environment, then I know that I don't need to read the SECRET_CREDENTIALS. But I know that when it's false then it's a production application that requires that secret to be defined.

If I were writing this in Elm then I'd want to read the IS_SANDBOX first, work out its value and then use that to pick which decoder I need to use, using andThen - https://package.elm-lang.org/packages/elm/json/latest/Json-Decode#andThen. I could also use succeed to produce the status on the type - https://package.elm-lang.org/packages/elm/json/latest/Json-Decode#succeed.

As far as I can tell, the library doesn't support this at the moment. Do you have any plans to add this?

Thanks!

@ben-eb
Copy link
Author

ben-eb commented Jun 21, 2023

I've since migrated my project to https://github.com/colinhacks/zod, so I don't need a fix for this. 馃憤

@ben-eb ben-eb closed this as completed Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant