A
arktype4mo ago
Dimava

Using `atLeastLength` on morphed array

How do I do
it("can use atLeastLength on piped array", () => {
const SortedArray = type("string[]").pipe(s => s.sort()).to('string[]')
const NonEmptySortedArray = SortedArray.atLeastLength(1)
attest(NonEmptySortedArray(['1', '2', '3'])).snap()
})
it("can use atLeastLength on piped array", () => {
const SortedArray = type("string[]").pipe(s => s.sort()).to('string[]')
const NonEmptySortedArray = SortedArray.atLeastLength(1)
attest(NonEmptySortedArray(['1', '2', '3'])).snap()
})
?
4 Replies
TizzySaurus
TizzySaurus4mo ago
In this case the array doesn't change in size during the pipe, so you can do type("string[]>1").pipe(...) But if you mean generally, then not sure
ssalbdivad
ssalbdivad4mo ago
I guess you're looking for this https://github.com/arktypeio/arktype/issues/1119
GitHub
withIn/withOut methods for constraining one side of a morph · Issu...
This would allow the inputs or outputs of morphs to be directly constrained via chaining as opposed to having to intersect (for input) or pipe (for output) from scratch. I did some initial work def...
Dimava
DimavaOP4mo ago
Will satifies work?
ssalbdivad
ssalbdivad4mo ago
satisfies applies to input narrow applies to output But those are for applying predicates But you can look at how it's implemented internally it's very trivial to use constrainOut There is just not an external syntax exposing that yet

Did you find this page helpful?