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

Function assertTupleArity

ark/type/parser/tupleExpressions.ts:427–444  ·  view source on GitHub ↗
(
	def: array,
	operator: TupleExpressionOperator,
	min: number,
	max = min
)

Source from the content-addressed store, hash-verified

425export type UnparsedTupleOperator = show<keyof UnparsedTupleExpressionInput>
426
427export const assertTupleArity = (
428 def: array,
429 operator: TupleExpressionOperator,
430 min: number,
431 max = min
432): void => {
433 if (def.length < min)
434 throwParseError(writeMissingRightOperandMessage(operator, ""))
435 if (def.length > max) {
436 throwParseError(
437 writeUnexpectedTupleElementsMessage(
438 operator,
439 min === max ? min : `${min} or ${max}`,
440 def.length
441 )
442 )
443 }
444}
445
446export const parseKeyOfTuple: IndexZeroParser<"keyof"> = (def, ctx) => {
447 assertTupleArity(def, "keyof", 2)

Callers 8

parsePropertyFunction · 0.90
parseKeyOfTupleFunction · 0.85
parseBranchTupleFunction · 0.85
parseArrayTupleFunction · 0.85
parseMorphTupleFunction · 0.85
parseNarrowTupleFunction · 0.85
parseMetaTupleFunction · 0.85

Calls 3

throwParseErrorFunction · 0.90

Tested by

no test coverage detected