Skip to content

Commit 8e4739f

Browse files
committed
Update inferred z.promise() type
1 parent e9e2790 commit 8e4739f

File tree

6 files changed

+5
-43
lines changed

6 files changed

+5
-43
lines changed

packages/zod/src/v4/classic/tests/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ test("z.json", () => {
749749
test("z.promise", async () => {
750750
const a = z.promise(z.string());
751751
type a = z.output<typeof a>;
752-
expectTypeOf<a>().toEqualTypeOf<string>();
752+
expectTypeOf<a>().toEqualTypeOf<Promise<string>>();
753753

754754
expect(await z.safeParseAsync(a, Promise.resolve("hello"))).toMatchObject({
755755
success: true,

packages/zod/src/v4/classic/tests/promise.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const promSchema = z.promise(
1010

1111
test("promise inference", () => {
1212
type promSchemaType = z.infer<typeof promSchema>;
13-
expectTypeOf<promSchemaType>().toEqualTypeOf<{ name: string; age: number }>();
13+
expectTypeOf<promSchemaType>().toEqualTypeOf<Promise<{ name: string; age: number }>>();
1414
});
1515

1616
test("promise parsing success", async () => {

packages/zod/src/v4/classic/tests/readonly.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ test("flat inference", () => {
4747
expectTypeOf<typeof readonlyNumberRecord._output>().toEqualTypeOf<Readonly<Record<string, number>>>();
4848
expectTypeOf<typeof readonlyObject._output>().toEqualTypeOf<{ readonly a: string; readonly 1: number }>();
4949
expectTypeOf<typeof readonlyEnum._output>().toEqualTypeOf<Readonly<testEnum>>();
50-
expectTypeOf<typeof readonlyPromise._output>().toEqualTypeOf<string>();
50+
expectTypeOf<typeof readonlyPromise._output>().toEqualTypeOf<Promise<string>>();
5151
});
5252

5353
// test("deep inference", () => {

packages/zod/src/v4/core/schemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4103,7 +4103,7 @@ export interface $ZodPromiseDef<T extends SomeType = $ZodType> extends $ZodTypeD
41034103
}
41044104

41054105
export interface $ZodPromiseInternals<T extends SomeType = $ZodType>
4106-
extends $ZodTypeInternals<core.output<T>, util.MaybeAsync<core.input<T>>> {
4106+
extends $ZodTypeInternals<Promise<core.output<T>>, util.MaybeAsync<core.input<T>>> {
41074107
def: $ZodPromiseDef<T>;
41084108
isst: never;
41094109
}
Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,5 @@
11
import { expect, test } from "vitest";
2-
// import * as z from "zod/v4/core";
32

43
test("z.function", () => {
54
expect(true).toEqual(true);
65
});
7-
8-
// test("z.function", () => {
9-
// const a = z.function({
10-
// args: z.tuple([z.string()]),
11-
// returns: z.string(),
12-
// });
13-
14-
// const myFunc = a.implement((name: string | number) => `Hello, ${name}!`);
15-
16-
// expect(myFunc("world")).toEqual("Hello, world!");
17-
// expect(() => myFunc(123 as any)).toThrow();
18-
19-
// // this won't run
20-
// () => {
21-
// // @ts-expect-error
22-
// const r = myFunc(123);
23-
// expectTypeOf(r).toEqualTypeOf<string>();
24-
// };
25-
// });
26-
27-
// test("z.function async", async () => {
28-
// const b = z.function({
29-
// args: z.tuple([z.string()]).$check(async (_) => {}),
30-
// returns: z.string().$check(async (_) => {}),
31-
// });
32-
// const myFuncAsync = b.implementAsync(async (name) => `Hello, ${name}!`);
33-
34-
// expect(await myFuncAsync("world")).toEqual("Hello, world!");
35-
// expect(myFuncAsync(123 as any)).rejects.toThrow();
36-
37-
// // this won't run
38-
// () => {
39-
// // @ts-expect-error
40-
// const r = myFuncAsync(123);
41-
// expectTypeOf(r).toEqualTypeOf<Promise<string>>();
42-
// };
43-
// });

packages/zod/src/v4/mini/tests/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ test("z.stringbool", () => {
789789
test("z.promise", async () => {
790790
const a = z.promise(z.string());
791791
type a = z.output<typeof a>;
792-
expectTypeOf<a>().toEqualTypeOf<string>();
792+
expectTypeOf<a>().toEqualTypeOf<Promise<string>>();
793793

794794
expect(await z.safeParseAsync(a, Promise.resolve("hello"))).toMatchObject({
795795
success: true,

0 commit comments

Comments
 (0)