Compiling to JavaScript results in `any` type

I have a TypeScript library that compiles down into JavaScript, and one of the d.ts files looks like this:
declare const Address: import("arktype/out/subtypes/string").StringType<import("arktype/out/keywords/ast").string.narrowed, {}>;
type Address = typeof Address.in.infer;
declare const Address: import("arktype/out/subtypes/string").StringType<import("arktype/out/keywords/ast").string.narrowed, {}>;
type Address = typeof Address.in.infer;
In this example, Address is of type any, whereas when I'm in TypeScript it's of type string
3 Replies
SynthLuvr
SynthLuvrOP8mo ago
To reproduce:
import { type } from "arktype";

const Address = type("string").narrow(() => true);
type Address = typeof Address.in.infer;

export { Address }
import { type } from "arktype";

const Address = type("string").narrow(() => true);
type Address = typeof Address.in.infer;

export { Address }
ssalbdivad
ssalbdivad8mo ago
Can you log an issue for this? It's something I'm interested in investigating and supporting but it's not trivial to ensure this never happens transitively and there are not tests for it yet
SynthLuvr
SynthLuvrOP2mo ago
hmm I'm still getting this issue with latest ArkType
const SeedToWallet = type(/^([a-z]+\s){23}[a-z]+$/).pipe((phrase, ctx) => {
const wallet = mayFail(() => walletFromSeed(phrase));
return wallet.ok ? wallet.data : ctx.error("valid mmemonic");
});

type Seed = typeof SeedToWallet.inferIn;
const SeedToWallet = type(/^([a-z]+\s){23}[a-z]+$/).pipe((phrase, ctx) => {
const wallet = mayFail(() => walletFromSeed(phrase));
return wallet.ok ? wallet.data : ctx.error("valid mmemonic");
});

type Seed = typeof SeedToWallet.inferIn;
Seed is correctly type string here. Compiled to JavaScript:
declare const Seed: import("arktype/internal/methods/morph.ts").MorphType<(In: string) => import("arktype/internal/attributes.ts").Out<FromSeed>, {}>;
type Seed = typeof Seed.inferIn;
declare const Seed: import("arktype/internal/methods/morph.ts").MorphType<(In: string) => import("arktype/internal/attributes.ts").Out<FromSeed>, {}>;
type Seed = typeof Seed.inferIn;
Seed is now type any Using:
{
"compilerOptions": {
"baseUrl": "./",
"target": "ESNext",
"module": "NodeNext",
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": false,
"moduleResolution": "nodenext",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"outDir": "dist"
},
"include": ["**/*"],
"exclude": ["node_modules", "dist"]
}
{
"compilerOptions": {
"baseUrl": "./",
"target": "ESNext",
"module": "NodeNext",
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": false,
"moduleResolution": "nodenext",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"outDir": "dist"
},
"include": ["**/*"],
"exclude": ["node_modules", "dist"]
}
It gets worse, anything returned by MorphType is any Ok I got it working. I needed to have arktype versions matching in both packages, even though arktype is set as a peer dependency

Did you find this page helpful?