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

Method constructor

ark/type/type.ts:311–389  ·  view source on GitHub ↗
($: InternalScope)

Source from the content-addressed store, hash-verified

309 TypeParserAttachments
310> {
311 constructor($: InternalScope) {
312 const attach = {
313 errors: ArkErrors,
314 hkt: Hkt,
315 $: $ as never,
316 raw: $.parse as never,
317 module: $.constructor.module,
318 scope: $.constructor.scope,
319 declare: $.declare as never,
320 define: $.define as never,
321 match: $.match as never,
322 generic: $.generic as never,
323 schema: $.schema as never,
324 // this won't be defined during bootstrapping, but externally always will be
325 keywords: $.ambient as never,
326 unit: ((value: unknown) =>
327 deferUnits([value], $) ?? $.unit(value)) as never,
328 enumerated: ((...values: unknown[]) =>
329 deferUnits(values, $) ?? $.enumerated(...values)) as never,
330 instanceOf: $.instanceOf,
331 valueOf: $.valueOf,
332 or: ((...branches: unknown[]) =>
333 deferUnion(branches, $) ?? ($.or as any)(...branches)) as never,
334 and: $.and,
335 merge: $.merge,
336 pipe: $.pipe,
337 fn: $.fn as never
338 } satisfies Omit<TypeParserAttachments, keyof Ark.typeAttachments>
339 super(
340 (...args) => {
341 if (args.length === 1) {
342 // treat as a simple definition
343 return deferDefinition(args[0], $) ?? $.parse(args[0])
344 }
345 if (
346 args.length === 2 &&
347 typeof args[0] === "string" &&
348 args[0][0] === "<" &&
349 args[0][args[0].length - 1] === ">"
350 ) {
351 // if there are exactly two args, the first of which looks like <${string}>,
352 // treat as a generic
353 const paramString = args[0].slice(1, -1)
354 const params = $.parseGenericParams(paramString, {})
355
356 return new GenericRoot(
357 params,
358 args[1],
359 $ as never,
360 $ as never,
361 null
362 ) as never
363 }
364 // otherwise, treat as a tuple expression. technically, this also allows
365 // non-expression tuple definitions to be parsed, but it's not a supported
366 // part of the API as specified by the associated types
367 return $.parse(args)
368 },

Callers

nothing calls this directly

Calls 7

deferUnitsFunction · 0.90
deferUnionFunction · 0.90
deferDefinitionFunction · 0.90
defineLazilyFunction · 0.90
bindKeywordsFunction · 0.85
parseGenericParamsMethod · 0.80
parseMethod · 0.45

Tested by

no test coverage detected