arktype 2.0.0-dev.2 → 2.0.0-dev.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35,70 +35,66 @@ export const parseObjectLiteral = (def: Dict, ctx: ParseContext): TypeNode => {
35
35
  // anywhere except for the beginning.
36
36
  // Discussion in ArkType Discord:
37
37
  // https://discord.com/channels/957797212103016458/1103023445035462678/1182814502471860334
38
- let hasSeenFirstKey = false
39
-
40
- const entries = stringAndSymbolicEntriesOf(def)
41
- for (const entry of entries) {
42
- const result = parseEntry(entry)
43
-
44
- if (result.kind === "spread") {
45
- if (hasSeenFirstKey) {
46
- return throwParseError(
47
- "Spread operator may only be used as the first key in an object"
48
- )
49
- }
50
-
51
- const spreadNode = ctx.scope.parse(result.innerValue, ctx)
52
-
53
- if (
54
- spreadNode.kind !== "intersection" ||
55
- !spreadNode.extends(keywords.object)
56
- ) {
57
- return throwParseError(
58
- writeInvalidSpreadTypeMessage(printable(result.innerValue))
59
- )
60
- }
61
-
62
- // For each key on spreadNode, add it to our object.
63
- // We filter out keys from the spreadNode that will be defined later on this same object
64
- // because the currently parsed definition will overwrite them.
65
- const requiredEntriesFromSpread = (
66
- spreadNode.props?.required ?? []
67
- ).filter((e) => !entries.some(([k]) => k === e.key))
68
-
69
- const optionalEntriesFromSpread = (
70
- spreadNode.props?.optional ?? []
71
- ).filter((e) => !entries.some(([k]) => k === e.key))
72
-
73
- required.push(...requiredEntriesFromSpread)
74
- optional.push(...optionalEntriesFromSpread)
75
-
76
- continue
38
+
39
+ const parsedEntries = stringAndSymbolicEntriesOf(def).map(parseEntry)
40
+ if (parsedEntries[0].kind === "spread") {
41
+ // remove the spread entry so we can iterate over the remaining entries
42
+ // expecting non-spread entries
43
+ const spreadEntry = parsedEntries.shift()!
44
+ const spreadNode = ctx.scope.parse(spreadEntry.innerValue, ctx)
45
+
46
+ if (
47
+ spreadNode.kind !== "intersection" ||
48
+ !spreadNode.extends(keywords.object)
49
+ ) {
50
+ return throwParseError(
51
+ writeInvalidSpreadTypeMessage(printable(spreadEntry.innerValue))
52
+ )
53
+ }
54
+
55
+ // TODO: move to props group merge in schema
56
+ // For each key on spreadNode, add it to our object.
57
+ // We filter out keys from the spreadNode that will be defined later on this same object
58
+ // because the currently parsed definition will overwrite them.
59
+ spreadNode.required?.forEach(
60
+ (spreadRequired) =>
61
+ !parsedEntries.some(
62
+ ({ innerKey }) => innerKey === spreadRequired.key
63
+ ) && required.push(spreadRequired)
64
+ )
65
+
66
+ spreadNode.optional?.forEach(
67
+ (spreadOptional) =>
68
+ !parsedEntries.some(
69
+ ({ innerKey }) => innerKey === spreadOptional.key
70
+ ) && optional.push(spreadOptional)
71
+ )
72
+ }
73
+ for (const entry of parsedEntries) {
74
+ if (entry.kind === "spread") {
75
+ return throwParseError(
76
+ "Spread operator may only be used as the first key in an object"
77
+ )
77
78
  }
78
79
 
79
80
  ctx.path.push(
80
81
  `${
81
- typeof result.innerKey === "symbol"
82
- ? `[${printable(result.innerKey)}]`
83
- : result.innerKey
82
+ typeof entry.innerKey === "symbol"
83
+ ? `[${printable(entry.innerKey)}]`
84
+ : entry.innerKey
84
85
  }`
85
86
  )
86
- const valueNode = ctx.scope.parse(result.innerValue, ctx)
87
-
88
- if (result.kind === "optional") {
89
- optional.push({
90
- key: result.innerKey,
91
- value: valueNode
92
- })
87
+ const value = ctx.scope.parse(entry.innerValue, ctx)
88
+ const inner: Inner<"required" | "optional"> = {
89
+ key: entry.innerKey,
90
+ value
91
+ }
92
+ if (entry.kind === "optional") {
93
+ optional.push(inner)
93
94
  } else {
94
- required.push({
95
- key: result.innerKey,
96
- value: valueNode
97
- })
95
+ required.push(inner)
98
96
  }
99
97
  ctx.path.pop()
100
-
101
- hasSeenFirstKey ||= true
102
98
  }
103
99
 
104
100
  return schema({
@@ -1,8 +1,9 @@
1
1
  import type {
2
+ Constraints,
2
3
  DateLiteral,
3
- Refinements,
4
4
  RegexLiteral,
5
5
  distill,
6
+ inferIntersection,
6
7
  is
7
8
  } from "@arktype/schema"
8
9
  import type {
@@ -24,7 +25,6 @@ import type {
24
25
  LimitLiteral
25
26
  } from "../string/reduce/shared.js"
26
27
  import type { StringLiteral } from "../string/shift/operand/enclosed.js"
27
- import type { inferIntersection } from "./intersections.js"
28
28
 
29
29
  export type inferAstRoot<ast, $, args> = inferAst<ast, $, args, {}>
30
30
 
@@ -34,7 +34,7 @@ export type inferAst<
34
34
  ast,
35
35
  $,
36
36
  args,
37
- refinements extends Refinements
37
+ refinements extends Constraints
38
38
  > = ast extends List
39
39
  ? inferExpression<ast, $, args, refinements>
40
40
  : inferTerminal<ast, $, args, refinements>
@@ -48,7 +48,7 @@ export type inferExpression<
48
48
  ast extends List,
49
49
  $,
50
50
  args,
51
- refinements extends Refinements
51
+ refinements extends Constraints
52
52
  > = ast extends GenericInstantiationAst
53
53
  ? inferDefinition<
54
54
  ast[0]["definition"],
@@ -122,7 +122,7 @@ export type inferTerminal<
122
122
  token,
123
123
  $,
124
124
  args,
125
- refinements extends Refinements
125
+ refinements extends Constraints
126
126
  > = token extends keyof args | keyof $
127
127
  ? {} extends refinements
128
128
  ? resolve<token, $, args>
@@ -1,4 +1,4 @@
1
- import type { Refinements } from "@arktype/schema"
1
+ import type { Constraints } from "@arktype/schema"
2
2
  import type {
3
3
  BigintLiteral,
4
4
  Completion,
package/parser/shared.ts CHANGED
@@ -12,7 +12,9 @@ type KeyParseResult<kind extends ParsedKeyKind = ParsedKeyKind> = {
12
12
  innerKey: string | symbol
13
13
  }
14
14
 
15
- type ValueParseResult<kind extends ParsedValueKind = ParsedValueKind> = {
15
+ export type EntryValueParseResult<
16
+ kind extends ParsedValueKind = ParsedValueKind
17
+ > = {
16
18
  kind: kind
17
19
  innerValue: unknown
18
20
  }
@@ -51,9 +53,9 @@ type validateObjectValueString<def, $, args> =
51
53
 
52
54
  type DefinitionEntry = readonly [string | symbol, unknown]
53
55
 
54
- const getInnerValue = (value: unknown): ValueParseResult => {
56
+ export const parseEntryValue = (value: unknown): EntryValueParseResult => {
55
57
  if (typeof value === "string") {
56
- if (value[value.length - 1] === "?") {
58
+ if (value.at(-1) === "?" && value.length > 1) {
57
59
  return {
58
60
  kind: "optional",
59
61
  innerValue: value.slice(0, -1)
@@ -63,7 +65,8 @@ const getInnerValue = (value: unknown): ValueParseResult => {
63
65
  if (value.length === 2 && value[1] === "?") {
64
66
  return {
65
67
  kind: "optional",
66
- innerValue: getInnerValue(value[0]).innerValue
68
+ // allow redundant optionality like ["string?", "?"]
69
+ innerValue: parseEntryValue(value[0]).innerValue
67
70
  }
68
71
  }
69
72
  }
@@ -87,7 +90,7 @@ export const parseEntry = ([key, value]: DefinitionEntry): EntryParseResult => {
87
90
  : key === "\\..."
88
91
  ? { innerKey: "...", kind: "required" }
89
92
  : { innerKey: key, kind: "required" }
90
- const valueParseResult = getInnerValue(value)
93
+ const valueParseResult = parseEntryValue(value)
91
94
  return {
92
95
  innerKey: keyParseResult.innerKey,
93
96
  innerValue: valueParseResult.innerValue,
package/parser/tuple.ts CHANGED
@@ -1,19 +1,25 @@
1
1
  import {
2
2
  keywords,
3
+ makeRootAndArrayPropertiesMutable,
3
4
  schema,
4
5
  type BaseMeta,
5
6
  type Morph,
6
7
  type MorphChildKind,
8
+ type MutableInner,
9
+ type Node,
7
10
  type Out,
8
11
  type Predicate,
9
12
  type Schema,
10
13
  type TypeNode,
14
+ type UnionChildKind,
11
15
  type extractIn,
12
16
  type extractOut,
17
+ type inferIntersection,
13
18
  type inferMorphOut,
14
19
  type inferNarrow
15
20
  } from "@arktype/schema"
16
21
  import {
22
+ append,
17
23
  isArray,
18
24
  objectKindOrDomainOf,
19
25
  printable,
@@ -21,6 +27,7 @@ import {
21
27
  type BuiltinObjectKind,
22
28
  type Constructor,
23
29
  type Domain,
30
+ type ErrorMessage,
24
31
  type List,
25
32
  type conform,
26
33
  type evaluate,
@@ -28,80 +35,144 @@ import {
28
35
  } from "@arktype/util"
29
36
  import type { ParseContext } from "../scope.js"
30
37
  import type { inferDefinition, validateDefinition } from "./definition.js"
31
- import type { inferIntersection } from "./semantic/intersections.js"
32
38
  import type { InfixOperator, PostfixExpression } from "./semantic/semantic.js"
33
39
  import { writeUnsatisfiableExpressionError } from "./semantic/validate.js"
34
40
  import {
35
41
  configureShallowDescendants,
36
- parseEntry,
42
+ parseEntryValue,
37
43
  type EntryParseResult,
44
+ type EntryValueParseResult,
45
+ type parseEntry,
38
46
  type validateObjectValue
39
47
  } from "./shared.js"
40
48
  import { writeMissingRightOperandMessage } from "./string/shift/operand/unenclosed.js"
41
49
  import type { BaseCompletions } from "./string/string.js"
42
50
 
43
- export const parseTuple = (def: List, ctx: ParseContext) =>
51
+ export const parseTuple = (def: readonly unknown[], ctx: ParseContext) =>
44
52
  maybeParseTupleExpression(def, ctx) ?? parseTupleLiteral(def, ctx)
45
53
 
46
- export const parseTupleLiteral = (def: List, ctx: ParseContext): TypeNode => {
47
- const props: unknown[] = []
48
- let variadicIndex: number | undefined
54
+ export const parseTupleLiteral = (
55
+ def: readonly unknown[],
56
+ ctx: ParseContext
57
+ ): TypeNode => {
58
+ let sequences: MutableInner<"sequence">[] = [{}]
49
59
  for (let i = 0; i < def.length; i++) {
50
- let elementDef = def[i]
51
60
  ctx.path.push(`${i}`)
52
- if (typeof elementDef === "string" && elementDef.startsWith("...")) {
53
- elementDef = elementDef.slice(3)
54
- if (variadicIndex !== undefined) {
55
- return throwParseError(multipleVariadicMesage)
56
- }
57
- variadicIndex = i
58
- } else if (
59
- isArray(elementDef) &&
60
- elementDef.length === 2 &&
61
- elementDef[0] === "..."
62
- ) {
63
- elementDef = elementDef[1]
64
- if (variadicIndex !== undefined) {
65
- return throwParseError(multipleVariadicMesage)
61
+ const parsedElementDef = parseSpreadable(def[i])
62
+ const element = ctx.scope.parse(parsedElementDef.innerValue, ctx)
63
+ if (parsedElementDef.spread) {
64
+ if (parsedElementDef.kind === "optional") {
65
+ return throwParseError(spreadOptionalMessage)
66
66
  }
67
- variadicIndex = i
68
- }
69
- const parsedEntry = parseEntry([`${i}`, elementDef])
70
- const value = ctx.scope.parse(parsedEntry.innerValue, ctx)
71
- if (variadicIndex === i) {
72
- if (!value.extends(keywords.Array)) {
73
- return throwParseError(writeNonArrayRestMessage(elementDef))
67
+ if (!element.extends(keywords.Array)) {
68
+ return throwParseError(writeNonArraySpreadMessage(element))
74
69
  }
75
- // TODO: Fix builtins.arrayIndexTypeNode()
76
- const elementType = value.getPath()
77
- // TODO: first variadic i
78
- props.push({ key: keywords.number, value: elementType })
70
+ // a spread must be distributed over branches e.g.:
71
+ // def: [string, ...(number[] | [true, false])]
72
+ // nodes: [string, ...number[]] | [string, true, false]
73
+ sequences = sequences.flatMap((base) =>
74
+ // since appendElement mutates base, we have to shallow-ish clone it for each branch
75
+ element.branches.map((branch) =>
76
+ appendSpreadBranch(makeRootAndArrayPropertiesMutable(base), branch)
77
+ )
78
+ )
79
79
  } else {
80
- props.push({
81
- key: {
82
- name: `${i}`,
83
- prerequisite: false,
84
- optional: parsedEntry.kind === "optional"
85
- },
86
- value
87
- })
80
+ sequences = sequences.map((base) =>
81
+ appendElement(
82
+ base,
83
+ parsedElementDef.kind === "optional" ? "optional" : "required",
84
+ element
85
+ )
86
+ )
88
87
  }
89
88
  ctx.path.pop()
90
89
  }
91
- if (variadicIndex === undefined) {
92
- props.push({
93
- key: {
94
- name: "length",
95
- prerequisite: true,
96
- optional: false
97
- },
98
- value: schema({ unit: def.length })
99
- })
90
+ return schema(
91
+ ...sequences.map((sequence) => ({
92
+ basis: Array,
93
+ sequence
94
+ }))
95
+ )
96
+ }
97
+
98
+ const appendElement = (
99
+ base: MutableInner<"sequence">,
100
+ kind: "optional" | "required" | "variadic",
101
+ element: TypeNode
102
+ ): MutableInner<"sequence"> => {
103
+ switch (kind) {
104
+ case "required":
105
+ if (base.optionals)
106
+ // e.g. [string?, number]
107
+ return throwParseError(requiredPostOptionalMessage)
108
+ if (base.variadic) {
109
+ // e.g. [...string[], number]
110
+ base.postfix = append(base.postfix, element)
111
+ } else {
112
+ // e.g. [string, number]
113
+ base.prefix = append(base.prefix, element)
114
+ }
115
+ return base
116
+ case "optional":
117
+ if (base.variadic)
118
+ // e.g. [...string[], number?]
119
+ return throwParseError(optionalPostVariadicMessage)
120
+ // e.g. [string, number?]
121
+ base.optionals = append(base.optionals, element)
122
+ return base
123
+ case "variadic":
124
+ // e.g. [...string[], number, ...string[]]
125
+ if (base.postfix) throwParseError(multipleVariadicMesage)
126
+ if (base.variadic) {
127
+ if (!base.variadic.equals(element)) {
128
+ // e.g. [...string[], ...number[]]
129
+ throwParseError(multipleVariadicMesage)
130
+ }
131
+ // e.g. [...string[], ...string[]]
132
+ // do nothing, second spread doesn't change the type
133
+ } else {
134
+ // e.g. [string, ...number[]]
135
+ base.variadic = element
136
+ }
137
+ return base
138
+ }
139
+ }
140
+
141
+ const appendSpreadBranch = (
142
+ base: MutableInner<"sequence">,
143
+ branch: Node<UnionChildKind>
144
+ ): MutableInner<"sequence"> => {
145
+ const spread = branch.firstReferenceOfKind("sequence")
146
+ if (!spread) {
147
+ // the only array with no sequence reference is unknown[]
148
+ return appendElement(base, "variadic", keywords.unknown)
149
+ }
150
+ spread.prefix.forEach((node) => appendElement(base, "required", node))
151
+ spread.optionals.forEach((node) => appendElement(base, "optional", node))
152
+ spread.variadic && appendElement(base, "variadic", spread.variadic)
153
+ spread.postfix.forEach((node) => appendElement(base, "required", node))
154
+ return base
155
+ }
156
+
157
+ type TupleElementParseResult = EntryValueParseResult & { spread?: true }
158
+
159
+ const parseSpreadable = (elementDef: unknown): TupleElementParseResult => {
160
+ if (typeof elementDef === "string" && elementDef.startsWith("...")) {
161
+ // variadic string definition like "...string[]"
162
+ return { ...parseEntryValue(elementDef.slice(3)), spread: true }
163
+ }
164
+ if (
165
+ isArray(elementDef) &&
166
+ elementDef.length === 2 &&
167
+ elementDef[0] === "..."
168
+ ) {
169
+ // variadic tuple expression like ["...", { a: "1" }]
170
+ return { ...parseEntryValue(elementDef[1]), spread: true }
100
171
  }
101
- return schema(Array)
172
+ return parseEntryValue(elementDef)
102
173
  }
103
174
 
104
- export const maybeParseTupleExpression = (
175
+ const maybeParseTupleExpression = (
105
176
  def: List,
106
177
  ctx: ParseContext
107
178
  ): TypeNode | undefined => {
@@ -157,28 +228,32 @@ export type validateTupleLiteral<
157
228
  tail,
158
229
  $,
159
230
  args,
160
- [...result, validateTupleElement<head, tail, $, args>]
231
+ [...result, validateTupleElement<head, result, $, args>]
161
232
  >
162
233
  : result
163
234
 
164
- type validateTupleElement<head, tail, $, args> =
165
- head extends variadicExpression<infer operand>
166
- ? validateDefinition<operand, $, args> extends infer syntacticResult
167
- ? syntacticResult extends operand
168
- ? semanticallyValidateRestElement<
169
- operand,
170
- $,
171
- args
172
- > extends infer semanticResult
173
- ? semanticResult extends operand
174
- ? tail extends []
175
- ? head
176
- : prematureRestMessage
177
- : semanticResult
178
- : never
179
- : syntacticResult
180
- : never
181
- : validateObjectValue<head, $, args>
235
+ type validateTupleElement<
236
+ head,
237
+ result extends unknown[],
238
+ $,
239
+ args
240
+ > = head extends variadicExpression<infer operand>
241
+ ? validateDefinition<operand, $, args> extends infer syntacticResult
242
+ ? syntacticResult extends operand
243
+ ? semanticallyValidateRestElement<
244
+ operand,
245
+ $,
246
+ args
247
+ > extends infer semanticResult
248
+ ? semanticResult extends operand
249
+ ? Extract<result[number], variadicExpression> extends never
250
+ ? head
251
+ : ErrorMessage<multipleVariadicMessage>
252
+ : semanticResult
253
+ : never
254
+ : syntacticResult
255
+ : never
256
+ : validateObjectValue<head, $, args>
182
257
 
183
258
  type semanticallyValidateRestElement<operand, $, args> = inferDefinition<
184
259
  operand,
@@ -186,26 +261,39 @@ type semanticallyValidateRestElement<operand, $, args> = inferDefinition<
186
261
  args
187
262
  > extends infer result
188
263
  ? result extends never
189
- ? writeNonArrayRestMessage<operand>
264
+ ? writeNonArraySpreadMessage<operand>
190
265
  : isAny<result> extends true
191
- ? writeNonArrayRestMessage<operand>
266
+ ? writeNonArraySpreadMessage<operand>
192
267
  : result extends readonly unknown[]
193
268
  ? operand
194
- : writeNonArrayRestMessage<operand>
269
+ : writeNonArraySpreadMessage<operand>
195
270
  : never
196
271
 
197
- export const writeNonArrayRestMessage = <operand>(operand: operand) =>
198
- `Rest element ${
199
- typeof operand === "string" ? `'${operand}'` : ""
200
- } must be an array` as writeNonArrayRestMessage<operand>
272
+ export const writeNonArraySpreadMessage = <operand extends string | TypeNode>(
273
+ operand: operand
274
+ ) =>
275
+ `Spread element must be an array (was ${operand})` as writeNonArraySpreadMessage<operand>
201
276
 
202
- type writeNonArrayRestMessage<operand> = `Rest element ${operand extends string
203
- ? `'${operand}'`
204
- : ""} must be an array`
277
+ type writeNonArraySpreadMessage<operand> =
278
+ `Spread element must be an array${operand extends string
279
+ ? `(was ${operand})`
280
+ : ""}`
205
281
 
206
282
  export const multipleVariadicMesage = `A tuple may have at most one variadic element`
207
283
 
208
- type prematureRestMessage = typeof multipleVariadicMesage
284
+ type multipleVariadicMessage = typeof multipleVariadicMesage
285
+
286
+ export const requiredPostOptionalMessage = `A required element may not follow an optional element`
287
+
288
+ type requiredPostOptionalMessage = typeof requiredPostOptionalMessage
289
+
290
+ export const optionalPostVariadicMessage = `An optional element may not follow a variadic element`
291
+
292
+ type optionalPostVariadicMessage = typeof optionalPostVariadicMessage
293
+
294
+ export const spreadOptionalMessage = `A spread element cannot be optional`
295
+
296
+ type spreadOptionalMessage = typeof optionalPostVariadicMessage
209
297
 
210
298
  type inferTupleLiteral<
211
299
  def extends List,
package/scope.ts CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  domainOf,
11
11
  hasDomain,
12
12
  isThunk,
13
- map,
13
+ morph,
14
14
  throwParseError,
15
15
  type Dict,
16
16
  type evaluate,
@@ -399,7 +399,7 @@ export class Scope<r extends Resolutions = any> {
399
399
  names extends [] ? keyof r["exports"] & string : names[number]
400
400
  > {
401
401
  return addArkKind(
402
- map(this.export(...names) as Dict, (alias, value) => [
402
+ morph(this.export(...names) as Dict, (alias, value) => [
403
403
  `#${alias}`,
404
404
  value
405
405
  ]) as never,
@@ -444,7 +444,10 @@ export class Scope<r extends Resolutions = any> {
444
444
  }
445
445
  const namesToExport = names.length ? names : this.exportedNames
446
446
  return addArkKind(
447
- map(namesToExport, (_, name) => [name, this.exportCache![name]]) as never,
447
+ morph(namesToExport, (_, name) => [
448
+ name,
449
+ this.exportCache![name]
450
+ ]) as never,
448
451
  "module"
449
452
  ) as never
450
453
  }
@@ -458,7 +461,7 @@ const resolutionsOfModule = (typeSet: ExportCache) => {
458
461
  const v = typeSet[k]
459
462
  if (hasArkKind(v, "module")) {
460
463
  const innerResolutions = resolutionsOfModule(v as never)
461
- const prefixedResolutions = map(innerResolutions, (innerK, innerV) => [
464
+ const prefixedResolutions = morph(innerResolutions, (innerK, innerV) => [
462
465
  `${k}.${innerK}`,
463
466
  innerV
464
467
  ])
package/type.ts CHANGED
@@ -11,12 +11,13 @@ import {
11
11
  type extractIn,
12
12
  type extractOut,
13
13
  type includesMorphs,
14
+ type inferIntersection,
14
15
  type inferMorphOut,
15
16
  type inferNarrow
16
17
  } from "@arktype/schema"
17
18
  import {
18
19
  Callable,
19
- map,
20
+ morph,
20
21
  type Constructor,
21
22
  type Json,
22
23
  type conform
@@ -30,7 +31,6 @@ import {
30
31
  parseGenericParams,
31
32
  type GenericParamsParseError
32
33
  } from "./parser/generic.js"
33
- import type { inferIntersection } from "./parser/semantic/intersections.js"
34
34
  import { configureShallowDescendants } from "./parser/shared.js"
35
35
  import type {
36
36
  IndexOneOperator,
@@ -280,7 +280,7 @@ export const validateUninstantiatedGeneric = (g: Generic) => {
280
280
  // the base type here: https://github.com/arktypeio/arktype/issues/796
281
281
  {
282
282
  baseName: "generic",
283
- args: map(g.parameters, (_, name) => [name, keywords.unknown])
283
+ args: morph(g.parameters, (_, name) => [name, keywords.unknown])
284
284
  }
285
285
  )
286
286
  return g
@@ -293,7 +293,7 @@ export const generic = (
293
293
  ) => {
294
294
  return Object.assign(
295
295
  (...args: unknown[]) => {
296
- const argNodes = map(parameters, (i, param) => [
296
+ const argNodes = morph(parameters, (i, param) => [
297
297
  param,
298
298
  parseTypeRoot(args[i], scope)
299
299
  ])
@@ -1,46 +0,0 @@
1
- import type { MorphAst, Out } from "@arktype/schema"
2
- import {
3
- Hkt,
4
- type List,
5
- type conform,
6
- type evaluate,
7
- type intersectArrays,
8
- type isAny
9
- } from "@arktype/util"
10
-
11
- export type inferIntersection<l, r> = [l] extends [never]
12
- ? never
13
- : [r] extends [never]
14
- ? never
15
- : [l & r] extends [never]
16
- ? never
17
- : isAny<l | r> extends true
18
- ? any
19
- : l extends MorphAst<infer lIn, infer lOut>
20
- ? r extends MorphAst
21
- ? never
22
- : (In: evaluate<lIn & r>) => Out<lOut>
23
- : r extends MorphAst<infer rIn, infer rOut>
24
- ? (In: evaluate<rIn & l>) => Out<rOut>
25
- : [l, r] extends [object, object]
26
- ? intersectObjects<l, r> extends infer result
27
- ? result
28
- : never
29
- : l & r
30
-
31
- declare class MorphableIntersection extends Hkt.Kind {
32
- f: (
33
- In: conform<this[Hkt.key], [l: unknown, r: unknown]>
34
- ) => inferIntersection<(typeof In)[0], (typeof In)[1]>
35
- }
36
-
37
- type intersectObjects<l, r> = [l, r] extends [
38
- infer lList extends List,
39
- infer rList extends List
40
- ]
41
- ? intersectArrays<lList, rList, MorphableIntersection>
42
- : evaluate<
43
- {
44
- [k in keyof l]: k extends keyof r ? inferIntersection<l[k], r[k]> : l[k]
45
- } & Omit<r, keyof l>
46
- >