Open jacob-alford opened 3 weeks ago
This is a very common error in TS I have encountered many times but the circumstances are quite hard to pinpoint. See https://github.com/microsoft/TypeScript/issues/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.
I'm using @hono/arktype-validator
@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/@arktype+schema@0.1.22/node_modules/@arktype/schema/out/ast" but cannot be named.
Reproduction:
import * as ark from 'arktype'
export const Foo = ark.type(/\d+_\d+/).pipe((s) => {
const split = s.split('_')
const fst = split[0]
const snd = split[1]
if (fst === undefined || snd === undefined) {
return `Received unexpectedly invalid string ${split}, expected a string matching the pattern /\\d+_\\d/`
}
return Number(`${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
.
Hmm, well that is unfortunate and also very environment-dependent.
I would consider bundling @arktype/schema
as mentioned. I've opened an issue for that here:
https://github.com/arktypeio/arktype/issues/1049
As a potential stopgap, I will also try re-exporting inferred symbols from arktype
(including constrained
) in the next release to see if that helps.
Thank you for your help!
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
Report a bug
Hello, I have an issue while exporting arktype schemas using TypeScript. I get the following error:
🔎 Search Terms
cannot be named, without reference to, likely not portable, type annotation necessary, declaration files
🧩 Context
declaration: true
in tsconfig🧑💻 Repro
The above will result in the error found at the top of this issue. Note: TS must be configured to emit declaration files in order to see the error