Files
sugarr/src/core/config/env.ts
Fran Jurmanović 5140bc5a50 Widen loadEnv schema type and allow rest-sibling destructuring in lint
loadEnv's ZodSchema<T> parameter required schema input === output,
which breaks any schema using .transform() (e.g. AppConfigSchema's
boolean coercion). Widen to ZodType<T, ZodTypeDef, unknown>, matching
existing runtime behavior. Also allow ignoreRestSiblings in the
no-unused-vars rule so 'const { X, ...rest } = obj' omission tests
don't trip the linter.
2026-08-12 21:08:21 +02:00

13 lines
348 B
TypeScript

import type { ZodType, ZodTypeDef } from 'zod';
export function loadEnv<T>(
schema: ZodType<T, ZodTypeDef, unknown>,
source: NodeJS.ProcessEnv = process.env
): T {
const result = schema.safeParse(source);
if (!result.success) {
throw new Error(`Invalid environment configuration: ${result.error.message}`);
}
return result.data;
}