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.