-
Notifications
You must be signed in to change notification settings - Fork 66
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeScript: Validator return type is to broad when a list of choices is given #139
Comments
I'm having the exact same issue and it's funny enough you came across this just two hours ago :P https://github.com/af/envalid/blob/main/src/validators.ts#L65-L66 To me it seems that the validator would need to pass I have no idea of the implications for the rest of the library though, if this were to go into the default |
I feel like this is a bug (and possible regression from v6?)– There was some previous discussion about changing how choices are represented in the API. I considered doing this for v7 but wanted to get it out the door and there were already a bunch of API changes. But it'd be nice to have this kind of API where the type param wouldn't be necessary for this common use case |
I have bumped into the same error today, and I think I found a solution. PR coming soon. |
Closing as this should be addressed in #146. Check out the examples on that PR and please chime in if you foresee any issues before the next release |
👋 @af!
Here is a small improvement idea for the library, given that it is written in TypeScript now. When using choices and passing a specific type to a validator, the return type seems to remain too broad. Here is an example:
Adding
<AB>
afterenvalid.str
already helps – I am no longer able to typedefault: "C"
for example. This is great. However, forconst choice
to becomeAB
, it is sill necessary to typecast the value ofenv.CHOICE
as a workaround:It’d be ideal if
envalid
did this type casting for us when the value forchoices
is provided!The text was updated successfully, but these errors were encountered: