- An explicit value (anything other than
undefined) is passed straight through — a caller-supplied config always wins over the environment. - When the field is
undefined,process.env[envKey]is substituted. An env var set to the empty string is treated as unset (a common deploy footgun) so it doesn’t satisfy a.min(1)by accident. - The inner
schemathen validates the resolved value, keeping its exact semantics — regex,.min(1),.url(),.optional(),.default(...). When both the field and the env var are absent, a required inner schema raises its normal “required” error.
undefined, wrapping a
field inside a z.object leaves it a plain key on the parsed result — union
discriminators like "accessToken" in config keep working.