extend
@rotorsoft/act-root / act/src / extend
Function: extend()
extend<
S,T>(source,schema,target?):Readonly<S&T>
Defined in: libs/act/src/utils.ts:60
Validate source against schema and return a new object that merges
source over the optional target defaults. Used by config for
env-var-overrides-defaults patterns; safe to call elsewhere โ it never
mutates target.
Type Parametersโ
Sโ
S extends Record<string, unknown>
Tโ
T extends Record<string, unknown>
Parametersโ
sourceโ
Readonly<S>
schemaโ
ZodType<S>
target?โ
Readonly<T>
Returnsโ
Readonly<S & T>
Exampleโ
const schema = z.object({ host: z.string(), port: z.number() });
const cfg = extend({ port: 8080 }, schema, { host: "localhost", port: 80 });
// โ { host: "localhost", port: 8080 }
Throwsโ
ValidationError if source fails the schema.