A
arktype•2mo ago
JesusTheHun

`narrow` vs `satisfying`

I've ran across both functions, I can see the signatures are the same, but the type are not. I was wondering what the different is, between the two ?
7 Replies
Dimava
Dimava•2mo ago
One is for input another is for output Or something So it's different for morphs only
JesusTheHun
JesusTheHunOP•2mo ago
Or something
?? 😂
Dimava
Dimava•2mo ago
Well I didn't use it myself so can't say for sure
JesusTheHun
JesusTheHunOP•2mo ago
kk, I'll try to compare the two with in/out
TizzySaurus
TizzySaurus•2mo ago
narrow(predicate: Predicate): BaseRoot {
return this.constrainOut("predicate", predicate)
}

satisfying(predicate: Predicate): BaseRoot {
return this.constrain("predicate", predicate)
}
narrow(predicate: Predicate): BaseRoot {
return this.constrainOut("predicate", predicate)
}

satisfying(predicate: Predicate): BaseRoot {
return this.constrain("predicate", predicate)
}
this is the difference in the source code narrow applies the constraint to the output, whereas satisfying applies the constraint to the input
JesusTheHun
JesusTheHunOP•2mo ago
so to see an actual difference, I would need to pipe the type in order to alter its input, correct ?
TizzySaurus
TizzySaurus•2mo ago
There'd need to be some form of transform, yes. Not necessarily a .pipe() explicitly though. E.g.:
type("string.numeric.parse").narrow(x => {...}) // `x` is a number
type("string.numeric.parse").satisfying(x => {...}) // `x` is a string
type("string.numeric.parse").narrow(x => {...}) // `x` is a number
type("string.numeric.parse").satisfying(x => {...}) // `x` is a string

Did you find this page helpful?