type inference resolves types from scopes to never in union
When using types from scopes in a union, arktype will resolve some of them to be "never", however if you insert their definition directly it resolves the type correctly
Here is an example. If you paste this in the playground and hover of the out, the type will resolve to "never" in some places.
Interestingly the .expression tab in the playground resolves the native Typescript expression correctly
Is this a bug or am I misusing scopes in some way?
14 Replies
I did some digging and the problem seems to be that in the
NaryUnionParser
the scope is not passed to type.infer
When i change (nary.ts: line 22
)
to
it works.
Is there are reason why the scope is not passed to type.infer
here?You're right, that is a mistake! Would be happy to accept a PR (double check other n-ary operations as well to make sure scope is passed + add test) otherwise will fix in next release
Good digging 👍
One warning, if you name keywords like this with
.
, people might expect it to be a submodule, which is a built-in version of that syntax:
https://arktype.io/docs/scopes#submodulesthanks a lot for the quick response, I will open a pull request for this issue 🙂 https://github.com/arktypeio/arktype/issues/1422
GitHub
type inference resolves custom types from scopes to be "never" when...
Report a bug 🔎 Search Terms never union discriminated union scope 🧩 Context ArkType version: 2.1.19 TypeScript version (5.1+): 5.7.3 Other context you think may be relevant (JS flavor, OS, etc.): 🧑...
another quick question:
is there a reason why we do not reuse the
inferredX
properties when defining r
?
I want to say no, as long as it doesn't cause any types to break its certainly cleaner (though probably negligible in terms of perf due to caching)
Actually this change overall could be quite good for perf if you're not using the default scope because the missing
$
arg could cause the def to be parsed twicenice 😌
the PR is now ready for review :) https://github.com/arktypeio/arktype/pull/1423
GitHub
#1422: fix nary type inference for scopes by Flosi23 · Pull Reques...
fixes: #1422
Added scope $ to all nary type inference.
TODO: add tests
addressed and pushed your requested changes 🙂
Awesome thanks so much- very much appreciate your thoroughness here!
thanks to you for you blazingly fast response time and reviews!
First time I've heard blazingly fast in that context 😅
btw do you know when these changes will be released?
Should be in the next day or two hopefully with the JSON schema change I'm working on!