Skip to content

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

@antoine-pous

Description

@antoine-pous

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions