0

TypeError: Cannot read properties of undefined (reading 'extend'). The path to Base import is correct. Typescript sees extend field on Base schema.

base.policy.ts

import * as z from "zod";

const Base = z.object({
  one: z.any();
  two: z.any();
})

export { Base };

three.policy.ts

import * as z from "zod";
import { Base } from "./";

const Extended = Base.extend({
  three: z.any();
})

pi88a
  • 81
  • 7
  • 1
    I think the reason you're seeing an error is being lost by the simplifications you've made. The code as posted has a few syntax errors (`zod.object` won't work because you've imported as `z`, semicolons instead of commas after the `zod.any`s, exporting `BaseArgs` instead of `Base`) I tried out just the `Base` and `Extended` definitions and it works as expected after fixing those syntax errors. The error message you included seems like you might be making a mistake with imports (which would be the case if you import base but only export `BaseArgs`) – Souperman Aug 15 '22 at 11:28
  • Thank you for paying attention to my question. The code in the question is just a simplified example. I have edited it. The error still exists – pi88a Aug 15 '22 at 16:45
  • What I'm trying to say is that if you just have the code as written, there's no issue. See [this codesandbox](https://codesandbox.io/s/elated-tesla-qdz0zb?file=/src/index.ts) All I did was remove those semicolons again and use import statements that point at the files directly instead of saying `import { Base } from "./"` That import statement won't work unless you export Base from an `index` file in the same directory as `three.policy.ts` – Souperman Aug 15 '22 at 23:31

0 Answers0