type narrow issue on result
i have this really basic function
as far as I know, before upgrading the package, this worked fine more or less
however, now there's simply no type narrowing.
validated
shows the same type inside of the if check, as well as after it
am i doing something clearly wrong here?15 Replies
the type it shows is basically the union of the success and error types
Can you add the full repro context?
this repros
arktype 2.1.16
This narrows for me
interesting
Maybe something to do with your tsconfig somehow? Not sure but it's definitely not a general issue
ok 🤔 will dig into this
I would add something that makes it a type error that it's not narrowed (maybe it already is for you) and see if that error also exists when you run tsc from the cli
just rolled back the version and it's still here. no idea when i introduced this since i thought that tsc has been completing no problem, but i guess not
does anything look wrong here? if not i'll figure this out tomorrow, just wanna make sure nothing is immediately broken
hmm, nothing jumps out 🤷
ok, thank you. this is a tomorow issue then
seems like mismatched versions in my monorepo caused this
updating deps at 1am was a horrible idea
Ahh makes sense, I should have thought of that
Because of
instanceof
A lot of the time I try to avoid those issues by e.g. using string literal constants instead of symbols, but good reminder instanceof
will still fail if there are multiple resolutionswhy does the string literal avoid this?
also while i'm here- is there a substantial difference btwn checking if the result is instanceof
type.errors
vs ArkErrors
?There are other similar cases where a string literal instead of a symbol would help, not this one (although you could do something like
"byPath" in test
and it would work for both versions because it doesn't reference where the class is declared)
Generally best for many reasons though to make sure you have your versions aligned
type.errors
is just a reference to ArkErrors
they're identical
Honestly it's one of the better ways to find out you have mismatched versions I guess. Other things that can happen could be messier to debug hahtrue true. thanks for the help!