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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default and default:Dev should be of type string #155

Open
antoine-pous opened this issue Jun 10, 2021 · 1 comment
Open

default and default:Dev should be of type string #155

antoine-pous opened this issue Jun 10, 2021 · 1 comment

Comments

@antoine-pous
Copy link
Contributor

antoine-pous commented Jun 10, 2021

default and defaultDev should pass the validator like a normal value, then there's no reason to put something else than string.

Here's an example:

const toArray = makeValidator((input: string): string[] => {
  return input.split(',')
})

interface IEnv {
  readonly TEST: string[]
}

const env: IEnv = cleanEnv(process.env, {
  TEST: toArray({default: 'test,string'}) // Argument type {default: string} is not assignable to parameter type Spec<string[]> | undefined
})

const env2: IEnv = cleanEnv(process.env, {
  TEST: toArray({default: ['test','string']}) // input.split is not a function
})

This make the library inconsistent, in fact env inputs are always string and we parse them to type them correctly, we cannot trust default values and have to check them like regular env input, then default and defaultDev must be type of string and nothing else.

@tonyxiao
Copy link

Yes. further the current typing is broken.

This works, but fails typing
image

This passes typing, but breaks at runtime from passing Object into JSON.parse

image

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

Successfully merging a pull request may close this issue.

2 participants