You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TypeScript declaration error: a type annotation is necessary #1031
Hello, I have an issue while exporting arktype schemas using TypeScript. I get the following error:
The inferred type of 'Foo' cannot be named without a reference to '.pnpm/@[email protected]/node_modules/@arktype/schema'. This is likely not portable. A type annotation is necessary.ts(2742)
🔎 Search Terms
cannot be named, without reference to, likely not portable, type annotation necessary, declaration files
🧩 Context
ArkType version: 2.0.0-dev.26
TypeScript version (5.1+): 5.5.2
Other context you think may be relevant (JS flavor, OS, etc.): pnpm, turbo monorepo, using declaration: true in tsconfig
This is a very common error in TS I have encountered many times but the circumstances are quite hard to pinpoint. See microsoft/TypeScript#42873
Does adding @arktype/schema to your dependencies directly resolve the issue? If so, I can eventually look into a method for publishing such that the types will always be resolved, maybe by bundling it.
+1, in my case I was declaring an optional string type and the Type['inferIn'] of it is string.moreThanLength instead of just string like the non optional key.
@ssalbdivad Hello, yes adding @arktype/schema to dependencies did solve that issue. However, I ran into a similar issue now after resolving. It doesn't apply to my original example exactly, but here is a reproduction for my current issue:
Error:
Exported variable 'Foo' has or is using name 'constrained' from external module "/Users/jalford/Documents/git/project/node_modules/.pnpm/@[email protected]/node_modules/@arktype/schema/out/ast" but cannot be named.
Reproduction:
import*asarkfrom'arktype'exportconstFoo=ark.type(/\d+_\d+/).pipe((s)=>{constsplit=s.split('_')constfst=split[0]constsnd=split[1]if(fst===undefined||snd===undefined){return`Received unexpectedly invalid string ${split}, expected a string matching the pattern /\\d+_\\d/`}returnNumber(`${fst}${snd}`)},ark.type('integer'))
I believe the issue comes from .pipe(..., ark.type("integer")).
Just for reference, I'm taking a string like this: 123_45 to a number: 12345.
FWIW we switched from pnpm to yarn 4 and the issue is still happening.
However, the initial issue that I opened with (i.e. The inferred type of 'Foo'...) does not happen with our new yarn 4 config. So maybe it's a bug with pnpm workspaces, but I don't think it's the fault of arktype. That should affect your #1049
Activity
ssalbdivad commentedon Jul 9, 2024
This is a very common error in TS I have encountered many times but the circumstances are quite hard to pinpoint. See microsoft/TypeScript#42873
Does adding
@arktype/schemato your dependencies directly resolve the issue? If so, I can eventually look into a method for publishing such that the types will always be resolved, maybe by bundling it.NamesMT commentedon Jul 9, 2024
+1, in my case I was declaring an optional string type and the
Type['inferIn']of it isstring.moreThanLengthinstead of juststringlike the non optional key.I'm using
@hono/arktype-validatorrae-hill commentedon Jul 10, 2024
@ssalbdivad Hello, yes adding
@arktype/schemato dependencies did solve that issue. However, I ran into a similar issue now after resolving. It doesn't apply to my original example exactly, but here is a reproduction for my current issue:Error:
Reproduction:
I believe the issue comes from
.pipe(..., ark.type("integer")).Just for reference, I'm taking a string like this:
123_45to a number:12345.ssalbdivad commentedon Jul 10, 2024
Hmm, well that is unfortunate and also very environment-dependent.
I would consider bundling
@arktype/schemaas mentioned. I've opened an issue for that here:#1049
As a potential stopgap, I will also try re-exporting inferred symbols from
arktype(includingconstrained) in the next release to see if that helps.rae-hill commentedon Jul 10, 2024
Thank you for your help!
rae-hill commentedon Jul 15, 2024
FWIW we switched from pnpm to yarn 4 and the issue is still happening.
However, the initial issue that I opened with (i.e.
The inferred type of 'Foo'...) does not happen with our new yarn 4 config. So maybe it's a bug with pnpm workspaces, but I don't think it's the fault of arktype. That should affect your #1049ssalbdivad commentedon Jul 24, 2024
Closing this for now, but will continue to track additional remediation for this as part of #1049
NamesMT commentedon Jul 26, 2024
Another possible solution for this issue is adding
@ark/schemaintotsconfig.json'scompilerOptions.typesarray:{ "compilerOptions": { // ... "types": [ "@ark/schema" ] } }dikatok commentedon Aug 8, 2024
confirmed working on my workspace, without needing to install the
schemaorutildependenciesEDIT The dependencies resolution is broken again on
2.0.0-beta.5😞