zod
zod copied to clipboard
Cannot export reference to iso
I was migrating from v3 to v4 then ran into the below. It seems exporting objects from the z.Whatever namespace is ok but z.innerSomething.Whatever is not. Note that the issue only arises when re-exporting from a different file.
// foo.ts
import { z } from "zod/v4";
export const Foo = z.object({
yep: z.string().datetime().nullable(), // is deprecated though
nope: z.iso.datetime().nullable(), // no inline error here but see `index.ts`
thatWorksThough: <z.ZodNullable<z.ZodString>><unknown>z.iso.datetime().nullable()
})
// index.ts
export const Bar = { Foo }; // ts2742 error here, see below
export const Baz: { Foo: typeof Foo } = { Foo } // ok
See error in vscode:
tsconfig.json
{
"compilerOptions": {
"target": "ES2022",
"lib": ["ES2022"],
"module": "ESNext",
"moduleResolution": "bundler",
"rootDir": "src",
"declaration": true,
"declarationMap": true,
"outDir": "dist",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}
package.json
"dependencies": {
"zod": "^3.25.0"
},
"devDependencies": {
"typescript": "^5.8.2"
}