Report a bug
π Search Terms
=== query: must be an array ===
=== query: discriminated union Record ===
=== query: recursive union ===
=== query: Record discriminated ===
=== query: was object ===
π§© Context
| arktype |
@ark/schema |
result |
| 2.2.1 |
0.56.0 |
β
OK |
| 2.2.2 |
0.56.1 |
β ERR |
| 2.2.3 |
0.56.2 |
β ERR |
The regression is introduced in 2.2.2 (@ark/schema 0.56.0 β 0.56.1).
π§βπ» Repro
import { scope, type } from "arktype";
const Node = scope({
Number: { type: "'number'" },
Array: { type: "'array'", item: "Node" },
Unit: { type: "'unit'" },
Container: { things: "Record<string, Node>" }, // β remove this line β works
Node: "Number | Array | Unit",
}).export().Node;
// A perfectly valid Node of the `array` variant:
const out = Node({ type: "array", item: { type: "number" } });
console.log(out instanceof type.errors ? "ERR: " + out.summary : "OK");
// 2.2.1 β "OK"
// 2.2.2 / 2.2.3 β "ERR: must be an array (was object)"
Minimization notes
The bug requires all of:
- a discriminated union with β₯ 3 branches (2 branches do not trigger it);
- one branch being an array type whose
item recurses into the union
({ type: "'array'", item: "Node" });
- a
Record<string, Node> reference somewhere in the same scope.
Remove (3), or drop to 2 branches β the same value validates fine. It does not
depend on validation order β the mis-resolution is baked in at scope-build time.
Possibly related
This is the same fragile area as cyclic/recursive discriminated-union
discrimination:
Report a bug
π Search Terms
=== query: must be an array ===
=== query: discriminated union Record ===
=== query: recursive union ===
=== query: Record discriminated ===
=== query: was object ===
π§© Context
The regression is introduced in 2.2.2 (@ark/schema
0.56.0 β 0.56.1).π§βπ» Repro
Minimization notes
The bug requires all of:
itemrecurses into the union(
{ type: "'array'", item: "Node" });Record<string, Node>reference somewhere in the same scope.Remove (3), or drop to 2 branches β the same value validates fine. It does not
depend on validation order β the mis-resolution is baked in at scope-build time.
Possibly related
This is the same fragile area as cyclic/recursive discriminated-union
discrimination:
the wrong branch. That fix is already present in the working 2.2.1, so this
is a separate, newer regression.
Notably, [bug] inconsistent errors for unions with cyclesΒ #1630's pattern (a union variant with a
Part[]field) with avalid value crashes on 2.2.1 (
TypeError: this.<Alias>Apply is not a function) but is OK on 2.2.2 β so 2.2.2 fixed that crash while introducingthe
Record+ array-branch false-rejection reported here.