arktype icon indicating copy to clipboard operation
arktype copied to clipboard

Use the result with the shortest path when finalizing errors for a cyclic value

Open ssalbdivad opened this issue 2 months ago • 1 comments

A Boston TS attendee (please take credit if you see this) suggested this could be optimized using a breadth-first approach to traversal.

While changing the traversal pattern would likely incur a significant performance cost, for cyclic types, we already need to keep track of a map of which values have been checked by which types.

Currently, if the combination we're checking has already been checked (whether valid or not), we don't recheck it. We still don't need to recheck the value, but when this occurs, we could update the error path if the one we just encountered is shorter than the one that is stored.

In the example at https://arktype.io/docs/scopes/, , we should expect the following improvement:

❌ problems:

dependencies/0/dependencies/0/contributors/0/email must be a valid email (was 'david@sharktypeio')
contributors/0/email must be a valid email (was 'david@sharktypeio')
❌ problems:

contributors/0/email must be a valid email (was 'david@sharktypeio')

ssalbdivad avatar Apr 19 '24 15:04 ssalbdivad