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

Function appendVariadicElement

ark/type/parser/tupleLiteral.ts:169–187  ·  view source on GitHub ↗
(
	base: mutableInnerOfKind<"sequence">,
	element: BaseRoot
)

Source from the content-addressed store, hash-verified

167}
168
169const appendVariadicElement = (
170 base: mutableInnerOfKind<"sequence">,
171 element: BaseRoot
172): mutableInnerOfKind<"sequence"> => {
173 // e.g. [...string[], number, ...string[]]
174 if (base.postfix) throwParseError(multipleVariadicMesage)
175 if (base.variadic) {
176 if (!base.variadic.equals(element)) {
177 // e.g. [...string[], ...number[]]
178 throwParseError(multipleVariadicMesage)
179 }
180 // e.g. [...string[], ...string[]]
181 // do nothing, second spread doesn't change the type
182 } else {
183 // e.g. [string, ...number[]]
184 base.variadic = element.internal
185 }
186 return base
187}
188
189const appendSpreadBranch = (
190 base: mutableInnerOfKind<"sequence">,

Callers 1

appendSpreadBranchFunction · 0.85

Calls 2

throwParseErrorFunction · 0.90
equalsMethod · 0.65

Tested by

no test coverage detected