agent_patch
runs/2026-02-27__21-30-28__gpt-5-3-codex/flux-pr-5575/flux-pr-5575.1-of-1.2026-02-27__21-30-28__gpt-5-3-codex/agent-logs/agent.patch
4468 bytes
diff --git a/tmp/agent-patch-flux-pr-5575.1-of-1.2026-02-27__21-30-28__gpt-5-3-codex/app/packages/zod/src/v4/classic/schemas.ts b/app/packages/zod/src/v4/classic/schemas.ts
index 737446a..56132e1 100644
--- a/tmp/agent-patch-flux-pr-5575.1-of-1.2026-02-27__21-30-28__gpt-5-3-codex/app/packages/zod/src/v4/classic/schemas.ts
+++ b/app/packages/zod/src/v4/classic/schemas.ts
@@ -88,6 +88,10 @@ export interface ZodType<
): Promise<parse.ZodSafeParseResult<core.output<this>>>;
// refinements
+ refine<RefinedOutput extends core.output<this>>(
+ check: (arg: core.output<this>) => arg is RefinedOutput,
+ params?: string | core.$ZodCustomParams
+ ): this & core.$ZodType<RefinedOutput, core.input<this>>;
refine(check: (arg: core.output<this>) => unknown | Promise<unknown>, params?: string | core.$ZodCustomParams): this;
superRefine(
refinement: (arg: core.output<this>, ctx: core.$RefinementCtx<core.output<this>>) => void | Promise<void>
@@ -199,7 +203,7 @@ export const ZodType: core.$constructor<ZodType> = /*@__PURE__*/ core.$construct
inst.safeDecodeAsync = async (data, params) => parse.safeDecodeAsync(inst, data, params);
// refinements
- inst.refine = (check, params) => inst.check(refine(check, params));
+ inst.refine = ((check, params) => inst.check(refine(check, params))) as any;
inst.superRefine = (refinement) => inst.check(superRefine(refinement));
inst.overwrite = (fn) => inst.check(checks.overwrite(fn));
@@ -2275,11 +2279,15 @@ export function custom<O>(
return core._custom(ZodCustom, fn ?? (() => true), _params) as any;
}
+export function refine<T, RefinedOutput extends T>(
+ fn: (arg: NoInfer<T>) => arg is RefinedOutput,
+ _params?: string | core.$ZodCustomParams
+): core.$ZodCheck<RefinedOutput>;
export function refine<T>(
fn: (arg: NoInfer<T>) => util.MaybeAsync<unknown>,
_params: string | core.$ZodCustomParams = {}
): core.$ZodCheck<T> {
- return core._refine(ZodCustom, fn, _params);
+ return core._refine(ZodCustom, fn, _params) as any;
}
// superRefine
diff --git a/tmp/agent-patch-flux-pr-5575.1-of-1.2026-02-27__21-30-28__gpt-5-3-codex/app/packages/zod/src/v4/classic/tests/refine.test.ts b/app/packages/zod/src/v4/classic/tests/refine.test.ts
index 6eaff2d..e516b50 100644
--- a/tmp/agent-patch-flux-pr-5575.1-of-1.2026-02-27__21-30-28__gpt-5-3-codex/app/packages/zod/src/v4/classic/tests/refine.test.ts
+++ b/app/packages/zod/src/v4/classic/tests/refine.test.ts
@@ -1,4 +1,4 @@
-import { describe, expect, test } from "vitest";
+import { describe, expect, expectTypeOf, test } from "vitest";
import * as z from "zod/v4";
describe("basic refinement functionality", () => {
@@ -416,6 +416,24 @@ describe("chained refinements", () => {
});
});
+describe("type predicates", () => {
+ test("refine narrows output type when using a type predicate", () => {
+ const schema = z.string().refine((arg): arg is "a" => arg === "a");
+
+ expectTypeOf<z.input<typeof schema>>().toEqualTypeOf<string>();
+ expectTypeOf<z.output<typeof schema>>().toEqualTypeOf<"a">();
+
+ expect(schema.safeParse("a").success).toEqual(true);
+ expect(schema.safeParse("b").success).toEqual(false);
+ });
+
+ test("refine keeps output type when using a non-predicate check", () => {
+ const schema = z.string().refine((arg) => arg.length > 0);
+
+ expectTypeOf<z.output<typeof schema>>().toEqualTypeOf<string>();
+ });
+});
+
// Commented tests can be uncommented once type-checking issues are resolved
/*
describe("type refinement", () => {
diff --git a/tmp/agent-patch-flux-pr-5575.1-of-1.2026-02-27__21-30-28__gpt-5-3-codex/app/packages/zod/src/v4/mini/schemas.ts b/app/packages/zod/src/v4/mini/schemas.ts
index 51e4c2a..0b7b274 100644
--- a/tmp/agent-patch-flux-pr-5575.1-of-1.2026-02-27__21-30-28__gpt-5-3-codex/app/packages/zod/src/v4/mini/schemas.ts
+++ b/app/packages/zod/src/v4/mini/schemas.ts
@@ -1639,11 +1639,15 @@ export function custom<O = unknown, I = O>(
}
// refine
+export function refine<T, RefinedOutput extends T>(
+ fn: (arg: NoInfer<T>) => arg is RefinedOutput,
+ _params?: string | core.$ZodCustomParams
+): core.$ZodCheck<RefinedOutput>;
export function refine<T>(
fn: (arg: NoInfer<T>) => util.MaybeAsync<unknown>,
_params: string | core.$ZodCustomParams = {}
): core.$ZodCheck<T> {
- return core._refine(ZodMiniCustom, fn, _params);
+ return core._refine(ZodMiniCustom, fn, _params) as any;
}
// superRefine