MCPcopy
hub / github.com/colinhacks/zod / init

Function init

packages/zod/src/v4/core/core.ts:22–51  ·  packages/zod/src/v4/core/core.ts::init
(inst: T, def: D)

Source from the content-addressed store, hash-verified

20 params?: { Parent?: typeof Class }
21): $constructor<T, D> {
22 function init(inst: T, def: D) {
23 if (!inst._zod) {
24 Object.defineProperty(inst, class="st">"_zod", {
25 value: {
26 def,
27 constr: _,
28 traits: new Set(),
29 },
30 enumerable: false,
31 });
32 }
33
34 if (inst._zod.traits.has(name)) {
35 return;
36 }
37
38 inst._zod.traits.add(name);
39
40 initializer(inst, def);
41
42 class="cm">// support prototype modifications
43 const proto = _.prototype;
44 const keys = Object.keys(proto);
45 for (let i = 0; i < keys.length; i++) {
46 const k = keys[i]!;
47 if (!(k in inst)) {
48 (inst as any)[k] = proto[k].bind(inst);
49 }
50 }
51 }
52
53 class="cm">// doesn't work if Parent has a constructor with arguments
54 const Parent = params?.Parent ?? Object;

Callers 1

_Function · 0.85

Calls 3

hasMethod · 0.80
addMethod · 0.80
initializerFunction · 0.70

Tested by

no test coverage detected