8000 Using 3.25.68 and newer versions fails to compile: Types have separate declarations of a private property '_cached' · Issue #4903 · colinhacks/zod · GitHub
[go: up one dir, main page]

Skip to content

Using 3.25.68 and newer versions fails to compile: Types have separate declarations of a private property '_cached' #4903

Closed

Description

@seratch

Hi, first of all, I want to say thank you so much for maintaining this amazing project.

Overview

I am one of OpenAI's Agents SDK maintainers, and we recently started receiving TS transpilation error reports with zod 3.25.68 and all newer versions from our users. Here’s a summary of the issue:

  • Zod 3.25.67 and older versions are compatible with our SDK.
  • Starting from zod 3.25.68, tsc fails for all zod-related code on the SDK user side.
  • Our SDK code itself still compiles with any version of zod 3.x.

I will share the reproduction steps at the end of this report.

We need your help 🙇

Aside from quickly reporting this issue to the zod project, we would appreciate any advice you could offer to help us mitigate the issue for our users until it is resolved. Currently, we are recommending our users use zod@3.25.67 or older for their projects with our Agents SDK. If there’s anything we can do on our end, we’re happy to try it. Any information would be appreciated.

Repro steps

Here are the simplest repro steps:

Run the following commands to create package.json and install the dependencies:

npm init -y
npm i @openai/agents@0.0.10 typescript zod@3.25.67

Create tsconfig.json

{
  "compilerOptions": {
    "outDir": "./dist",
    "target": "es2022",
    "noImplicitAny": true,
    "module": "commonjs",
    "declaration": true,
    "declarationMap": true,
    "sourceMap": true,
    "strict": true,
    "esModuleInterop": true,
    "allowJs": false
  },
  "include": ["src/**/*"]
}

Create src/index.ts:

import { Agent, tool } from '@openai/agents';
import { z } from 'zod';

const getWeather = tool({
  name: 'get_weather',
  description: 'Get the weather for a given city',
  parameters: z.object({ city: z.string() }),
  async execute({ city }) {
    return `The weather in ${city} is sunny.`;
  },
});

const agent = new Agent({
  name: 'Haiku Agent',
  instructions: 'Always respond in haiku form.',
  outputType: z.object({ haiku: z.string() }),
  tools: [getWeather],
});

Let's start with a successful pattern. Run the TS compiler this way. This succeeds without any issues. Older versions than 3.25.67 get the same result.

npx tsc

Contrarily, here is the failure pattern. Install zod@3.25.68 or newer:

npm i zod@3.25.68

Run the TS compiler again:

npx tsc

You'll see the following errors:

src/index.ts:7:3 - error TS2322: Type 'ZodObject<{ city: ZodString; }, "strip", ZodTypeAny, { city: string; }, { city: string; }>' is not assignable to type 'JsonObjectSchemaStrict<any> | JsonObjectSchemaNonStrict<any> | ZodObject<any, UnknownKeysParam, ZodTypeAny, { ...; }, { ...; }> | undefined'.
  Type 'ZodObject<{ city: ZodString; }, "strip", ZodTypeAny, { city: string; }, { city: string; }>' is not assignable to type 'ZodObject<any, UnknownKeysParam, ZodTypeAny, { [x: string]: any; }, { [x: string]: any; }>'.
    Types have separate declarations of a private property '_cached'.

7   parameters: z.object({ city: z.string() }),
    ~~~~~~~~~~

  node_modules/@openai/agents-core/dist/tool.d.ts:266:5
    266     parameters: TParameters;
            ~~~~~~~~~~
    The expected type comes from property 'parameters' which is declared here on type 'ToolOptions<ToolInputParameters, unknown>'

src/index.ts:7:15 - error TS2589: Type instantiation is excessively deep and possibly infinite.

7   parameters: z.object({ city: z.string() }),
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

src/index.ts:8:9 - error TS2322: Type '({ city }: { city: any; }) => Promise<string>' is not assignable to type 'ToolExecuteFunction<JsonObjectSchemaStrict<any> | ZodObject<any, UnknownKeysParam, ZodTypeAny, { [x: string]: any; }, { [x: string]: any; }> | undefined, unknown> | ToolExecuteFunction<...>'.
  Type '({ city }: { city: any; }) => Promise<string>' is not assignable to type 'ToolExecuteFunction<JsonObjectSchemaStrict<any> | ZodObject<any, UnknownKeysParam, ZodTypeAny, { [x: string]: any; }, { [x: string]: any; }> | undefined, unknown>'.
    Types of parameters '__0' and 'input' are incompatible.
      Type 'unknown' is not assignable to type '{ city: any; }'.

8   async execute({ city }) {
          ~~~~~~~

  node_modules/@openai/agents-core/dist/tool.d.ts:274:5
    274     execute: ToolExecuteFunction<TParameters, Context>;
            ~~~~~~~
    The expected type comes from property 'execute' which is declared here on type 'ToolOptions<ToolInputParameters, unknown>'

src/index.ts:16:3 - error TS2322: Type 'ZodObject<{ haiku: ZodString; }, "strip", ZodTypeAny, { haiku: string; }, { haiku: string; }>' is not assignable to type 'AgentOutputType<unknown> | undefined'.
  Type 'ZodObject<{ haiku: ZodString; }, "strip", ZodTypeAny, { haiku: string; }, { haiku: string; }>' is not assignable to type 'ZodObject<any, UnknownKeysParam, ZodTypeAny, { [x: string]: any; }, { [x: string]: any; }> | JsonSchemaDefinition'.
    Type 'ZodObject<{ haiku: ZodString; }, "strip", ZodTypeAny, { haiku: string; }, { haiku: string; }>' is not assignable to type 'ZodObject<any, UnknownKeysParam, ZodTypeAny, { [x: string]: any; }, { [x: string]: any; }>'.
      Types have separate declarations of a private property '_cached'.

16   outputType: z.object({ haiku: z.string() }),
     ~~~~~~~~~~

  node_modules/@openai/agents-core/dist/agent.d.ts:145:5
    145     outputType: TOutput;
            ~~~~~~~~~~
    The expected type comes from property 'outputType' which is declared here on type '{ name: string; instructions?: string | ((runContext: RunContext<unknown>, agent: Agent<unknown, AgentOutputType<unknown>>) => string | Promise<string>) | undefined; ... 12 more ...; resetToolChoice?: boolean | undefined; }'


Found 4 errors in the same file, starting at: src/index.ts:7

Activity

  1. added 3 commits that reference this issue on Jul 22, 2025
    b37aa3e
    9bf81ac
    815f745
  2. seratch commented on Jul 23, 2025

    @seratch
    Author

    @colinhacks Thank you so much for looking into this issue and resolving it in 4.0.6.

    I've confirmed the "_cached" property issue disappeared, but now the same code gets the following tsc error "error TS2589: Type instantiation is excessively deep and possibly infinite" with 4.0.6, 4.0.7, and 4.0.8 + "zod/v3".

    Should I create a new issue for it? Also, if there is anything possibly I can do on our side to prevent this from happening for our users, I'd love to try anything for it 🙇

    src/index.ts:7:3 - error TS2322: Type 'ZodObject<{ city: ZodString; }, "strip", ZodTypeAny, { city: string; }, { city: string; }>' is not assignable to type 'JsonObjectSchemaStrict<any> | JsonObjectSchemaNonStrict<any> | ZodObject<any, UnknownKeysParam, ZodTypeAny, { ...; }, { ...; }> | undefined'.
      Type 'ZodObject<{ city: ZodString; }, "strip", ZodTypeAny, { city: string; }, { city: string; }>' is not assignable to type 'ZodObject<any, UnknownKeysParam, ZodTypeAny, { [x: string]: any; }, { [x: string]: any; }>'.
        Property '_cached' is private in type 'ZodObject<any, UnknownKeysParam, ZodTypeAny, { [x: string]: any; }, { [x: string]: any; }>' but not in type 'ZodObject<{ city: ZodString; }, "strip", ZodTypeAny, { city: string; }, { city: string; }>'.
    
    7   parameters: z.object({ city: z.string() }),
        ~~~~~~~~~~
    
      node_modules/@openai/agents/node_modules/@openai/agents-core/dist/tool.d.ts:266:5
        266     parameters: TParameters;
                ~~~~~~~~~~
        The expected type comes from property 'parameters' which is declared here on type 'ToolOptions<ToolInputParameters, unknown>'
    
    src/index.ts:7:15 - error TS2589: Type instantiation is excessively deep and possibly infinite.
    
    7   parameters: z.object({ city: z.string() }),
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    src/index.ts:8:9 - error TS2322: Type '({ city }: { city: any; }) => Promise<string>' is not assignable to type 'ToolExecuteFunction<JsonObjectSchemaStrict<any> | ZodObject<any, UnknownKeysParam, ZodTypeAny, { [x: string]: any; }, { [x: string]: any; }> | undefined, unknown> | ToolExecuteFunction<...>'.
      Type '({ city }: { city: any; }) => Promise<string>' is not assignable to type 'ToolExecuteFunction<JsonObjectSchemaStrict<any> | ZodObject<any, UnknownKeysParam, ZodTypeAny, { [x: string]: any; }, { [x: string]: any; }> | undefined, unknown>'.
        Types of parameters '__0' and 'input' are incompatible.
          Type 'unknown' is not assignable to type '{ city: any; }'.
    
    8   async execute({ city }) {
              ~~~~~~~
    
      node_modules/@openai/agents/node_modules/@openai/agents-core/dist/tool.d.ts:274:5
        274     execute: ToolExecuteFunction<TParameters, Context>;
                ~~~~~~~
        The expected type comes from property 'execute' which is declared here on type 'ToolOptions<ToolInputParameters, unknown>'
    
    src/index.ts:16:3 - error TS2322: Type 'ZodObject<{ haiku: ZodString; }, "strip", ZodTypeAny, { haiku: string; }, { haiku: string; }>' is not assignable to type 'AgentOutputType<unknown> | undefined'.
      Type 'ZodObject<{ haiku: ZodString; }, "strip", ZodTypeAny, { haiku: string; }, { haiku: string; }>' is not assignable to type 'ZodObject<any, UnknownKeysParam, ZodTypeAny, { [x: string]: any; }, { [x: string]: any; }> | JsonSchemaDefinition'.
        Type 'ZodObject<{ haiku: ZodString; }, "strip", ZodTypeAny, { haiku: string; }, { haiku: string; }>' is not assignable to type 'ZodObject<any, UnknownKeysParam, ZodTypeAny, { [x: string]: any; }, { [x: string]: any; }>'.
          Property '_cached' is private in type 'ZodObject<any, UnknownKeysParam, ZodTypeAny, { [x: string]: any; }, { [x: string]: any; }>' but not in type 'ZodObject<{ haiku: ZodString; }, "strip", ZodTypeAny, { haiku: string; }, { haiku: string; }>'.
    
    16   outputType: z.object({ haiku: z.string() }),
         ~~~~~~~~~~
    
      node_modules/@openai/agents/node_modules/@openai/agents-core/dist/agent.d.ts:145:5
        145     outputType: TOutput;
                ~~~~~~~~~~
        The expected type comes from property 'outputType' which is declared here on type '{ name: string; instructions?: string | ((runContext: RunContext<unknown>, agent: Agent<unknown, AgentOutputType<unknown>>) => string | Promise<string>) | undefined; ... 12 more ...; resetToolChoice?: boolean | undefined; }'
    
    
    Found 4 errors in the same file, starting at: src/index.ts:7
    

    We don't support v4 at this moment, but just for your information, here is the error with "zod" / "zod/v4" in 4.0.6, 4.0.7, and 4.0.8:

    src/index.ts:7:3 - error TS2322: Type 'ZodObject<{ city: ZodString; }, $strip>' is not assignable to type 'JsonObjectSchemaStrict<any> | JsonObjectSchemaNonStrict<any> | ZodObject<any, UnknownKeysParam, ZodTypeAny, { ...; }, { ...; }> | undefined'.
      Type 'ZodObject<{ city: ZodString; }, $strip>' is missing the following properties from type 'ZodObject<any, UnknownKeysParam, ZodTypeAny, { [x: string]: any; }, { [x: string]: any; }>': _cached, _getCached, _parse, nonstrict, and 13 more.
    
    7   parameters: z.object({ city: z.string() }),
        ~~~~~~~~~~
    
      node_modules/@openai/agents/node_modules/@openai/agents-core/dist/tool.d.ts:266:5
        266     parameters: TParameters;
                ~~~~~~~~~~
        The expected type comes from property 'parameters' which is declared here on type 'ToolOptions<ToolInputParameters, unknown>'
    
    src/index.ts:8:9 - error TS2322: Type '({ city }: { city: any; }) => Promise<string>' is not assignable to type 'ToolExecuteFunction<JsonObjectSchemaStrict<any> | ZodObject<any, UnknownKeysParam, ZodTypeAny, { [x: string]: any; }, { [x: string]: any; }> | undefined, unknown> | ToolExecuteFunction<...>'.
      Type '({ city }: { city: any; }) => Promise<string>' is not assignable to type 'ToolExecuteFunction<JsonObjectSchemaStrict<any> | ZodObject<any, UnknownKeysParam, ZodTypeAny, { [x: string]: any; }, { [x: string]: any; }> | undefined, unknown>'.
        Types of parameters '__0' and 'input' are incompatible.
          Type 'unknown' is not assignable to type '{ city: any; }'.
    
    8   async execute({ city }) {
              ~~~~~~~
    
      node_modules/@openai/agents/node_modules/@openai/agents-core/dist/tool.d.ts:274:5
        274     execute: ToolExecuteFunction<TParameters, Context>;
                ~~~~~~~
        The expected type comes from property 'execute' which is declared here on type 'ToolOptions<ToolInputParameters, unknown>'
    
    src/index.ts:16:3 - error TS2322: Type 'ZodObject<{ haiku: ZodString; }, $strip>' is not assignable to type 'AgentOutputType<unknown> | undefined'.
      Type 'ZodObject<{ haiku: ZodString; }, $strip>' is not assignable to type 'ZodObject<any, UnknownKeysParam, ZodTypeAny, { [x: string]: any; }, { [x: string]: any; }> | JsonSchemaDefinition'.
        Type 'ZodObject<{ haiku: ZodString; }, $strip>' is missing the following properties from type 'ZodObject<any, UnknownKeysParam, ZodTypeAny, { [x: string]: any; }, { [x: string]: any; }>': _cached, _getCached, _parse, nonstrict, and 13 more.
    
    16   outputType: z.object({ haiku: z.string() }),
         ~~~~~~~~~~
    
      node_modules/@openai/agents/node_modules/@openai/agents-core/dist/agent.d.ts:145:5
        145     outputType: TOutput;
                ~~~~~~~~~~
        The expected type comes from property 'outputType' which is declared here on type '{ name: string; instructions?: string | ((runContext: RunContext<unknown>, agent: Agent<unknown, AgentOutputType<unknown>>) => string | Promise<string>) | undefined; ... 12 more ...; resetToolChoice?: boolean | undefined; }'
    
    
    Found 3 errors in the same file, starting at: src/index.ts:7
    
  3. added a commit that references this issue on Jul 23, 2025
    7dd7484
  4. seratch commented on Jul 25, 2025

    @seratch
    Author

    For visibility, I created a new issue for my previous comment: #4984 If there is anything I can do for resolving this on my end, please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0