Skip to content

InferOutput behavior for nullish fields is inconsistent. #1104

Open
@cometkim

Description

@cometkim
const EnvSchema = v.object({
  STAGE: v.pipe(
    v.nullish(v.picklist(['alpha', 'prod'])),
    v.transform(input => {
      switch (input) {
        case 'alpha': return 'alpha';
        case 'prod': return 'production';
        default: return 'development';
      }
    }),
  ),
});

type EnvInput = v.InferInput<typeof EnvSchema>;
type EnvOutput = v.InferOutput<typeof EnvSchema>;

EnvSchema parses { STAGE?: "alpha" | "prod" | undefined | null } and transforms it to { STAGE: "alpha" | "production" | "development" }

So I expected the EnvOutput type to be { STAGE: "alpha" | "production" | "development" }, but it's { STAGE?: "alpha" | "production" | "development" | undefined }

This is the same for nullish and optional, but works as expected with nullable and undefinedable.

Metadata

Metadata

Assignees

Labels

duplicateThis issue or pull request already exists

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions