MCPcopy Create free account
hub / github.com/arktypeio/arktype / constructor

Method constructor

ark/schema/generic.ts:112–165  ·  view source on GitHub ↗
(
		paramDefs: array<GenericParamDef>,
		bodyDef: bodyDef,
		$: BaseScope,
		arg$: BaseScope,
		hkt: Hkt.constructor | null,
		alias?: string
	)

Source from the content-addressed store, hash-verified

110 private pendingChecks: Record<string, () => void> = {}
111
112 constructor(
113 paramDefs: array<GenericParamDef>,
114 bodyDef: bodyDef,
115 $: BaseScope,
116 arg$: BaseScope,
117 hkt: Hkt.constructor | null,
118 alias?: string
119 ) {
120 super((...args: any[]) => {
121 if (args.length !== this.names.length) {
122 return throwParseError(
123 writeArgCountMessage(
124 this.alias ?? "generic",
125 this.names,
126 args.map(arg => this.arg$.parse(arg).expression)
127 )
128 )
129 }
130 const argNodes = flatMorph(this.names, (i, name) => [
131 name,
132 this.arg$.parse(args[i])
133 ]) as GenericArgResolutions<any>
134 const argList = this.names.map(name => argNodes[name])
135 const key = argList.map(identityOf).join(",")
136 if (
137 argList.some(
138 (arg, i) =>
139 !this.constraints[i].isUnknown() &&
140 !(isResolvable(arg) && isResolvable(this.constraints[i]))
141 )
142 ) {
143 const depth = openInstancesByGeneric.get(this) ?? 0
144 return this.arg$.lazilyResolve(
145 () => this.instantiate(key, argNodes, depth),
146 `${this.id}<${key}>`,
147 this.alias ?? "generic",
148 argList
149 )
150 }
151 return this.instantiate(key, argNodes)
152 })
153
154 this.paramDefs = paramDefs
155 this.bodyDef = bodyDef
156 this.$ = $
157 this.arg$ = arg$
158 this.hkt = hkt
159 this.description =
160 hkt ?
161 (new hkt().description ?? `a generic type for ${functionNameOf(hkt)}`)
162 : "a generic type"
163 this.alias = alias
164 if ($.resolved || !alias) void this.baseInstance
165 }
166
167 get id(): NodeId {
168 return this.memo("id", () => registerNodeId(this.alias ?? "generic"))

Callers

nothing calls this directly

Calls 9

instantiateMethod · 0.95
throwParseErrorFunction · 0.90
flatMorphFunction · 0.90
isResolvableFunction · 0.90
functionNameOfFunction · 0.90
writeArgCountMessageFunction · 0.85
mapMethod · 0.65
getMethod · 0.65
parseMethod · 0.45

Tested by

no test coverage detected