A
arktype3mo 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
TizzySaurus3mo 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
ssalbdivad3mo 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
DimavaOP3mo ago
Will satifies work?
ssalbdivad
ssalbdivad3mo 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
Want results from more Discord servers?
Add your server