zod 4.3.0-canary.20251216T030621 → 4.3.0-canary.20251216T031750

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod",
3
- "version": "4.3.0-canary.20251216T030621",
3
+ "version": "4.3.0-canary.20251216T031750",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Colin McDonnell <zod@colinhacks.com>",
@@ -274,6 +274,58 @@ test("function with async refinements", async () => {
274
274
  expect(results).toEqual(["fail", "success"]);
275
275
  });
276
276
 
277
+ test("implement async with transforms", async () => {
278
+ const typeGuard = (data: string): data is "1234" => data === "1234";
279
+ const codeSchema = z.string().transform((data, ctx) => {
280
+ if (typeGuard(data)) {
281
+ return data;
282
+ } else {
283
+ ctx.addIssue({
284
+ code: z.ZodIssueCode.custom,
285
+ message: "Invalid code",
286
+ });
287
+ return z.NEVER;
288
+ }
289
+ });
290
+ const inputSchema = z.object({
291
+ code: codeSchema,
292
+ });
293
+ const outputSchema = z.object({
294
+ data: z.array(z.string()).default([]),
295
+ });
296
+ const fnImplementation = async (data: z.infer<typeof inputSchema>): Promise<z.infer<typeof outputSchema>> => {
297
+ return {
298
+ data: [data.code],
299
+ };
300
+ };
301
+ const schema = z.function().input([inputSchema]).output(outputSchema);
302
+
303
+ const func = schema.implementAsync(fnImplementation);
304
+ type TheInterface = {
305
+ myFunction: (data: z.infer<typeof inputSchema>) => Promise<z.infer<typeof outputSchema>>;
306
+ };
307
+ const theImplementation: TheInterface = {
308
+ myFunction: func,
309
+ };
310
+ const results = [];
311
+ try {
312
+ await theImplementation.myFunction({
313
+ code: "1234",
314
+ });
315
+ results.push("success");
316
+ } catch (_) {
317
+ results.push("fail");
318
+ }
319
+ try {
320
+ await func({ data: "asdflkjasdflkjsf" } as any);
321
+ results.push("success");
322
+ } catch (_) {
323
+ results.push("fail");
324
+ }
325
+
326
+ expect(results).toEqual(["success", "fail"]);
327
+ });
328
+
277
329
  test("non async function with async refinements should fail", async () => {
278
330
  const func = z
279
331
  .function()
@@ -4056,7 +4056,7 @@ export type $InferOuterFunctionType<Args extends $ZodFunctionIn, Returns extends
4056
4056
 
4057
4057
  export type $InferOuterFunctionTypeAsync<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (
4058
4058
  ...args: $ZodFunctionIn extends Args ? never[] : core.input<Args>
4059
- ) => util.MaybeAsync<core.output<Returns>>;
4059
+ ) => Promise<core.output<Returns>>;
4060
4060
 
4061
4061
  export interface $ZodFunctionDef<
4062
4062
  In extends $ZodFunctionIn = $ZodFunctionIn,
@@ -1054,7 +1054,7 @@ export type $ZodFunctionOut = $ZodType;
1054
1054
  export type $InferInnerFunctionType<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (...args: $ZodFunctionIn extends Args ? never[] : core.output<Args>) => core.input<Returns>;
1055
1055
  export type $InferInnerFunctionTypeAsync<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (...args: $ZodFunctionIn extends Args ? never[] : core.output<Args>) => util.MaybeAsync<core.input<Returns>>;
1056
1056
  export type $InferOuterFunctionType<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (...args: $ZodFunctionIn extends Args ? never[] : core.input<Args>) => core.output<Returns>;
1057
- export type $InferOuterFunctionTypeAsync<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (...args: $ZodFunctionIn extends Args ? never[] : core.input<Args>) => util.MaybeAsync<core.output<Returns>>;
1057
+ export type $InferOuterFunctionTypeAsync<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (...args: $ZodFunctionIn extends Args ? never[] : core.input<Args>) => Promise<core.output<Returns>>;
1058
1058
  export interface $ZodFunctionDef<In extends $ZodFunctionIn = $ZodFunctionIn, Out extends $ZodFunctionOut = $ZodFunctionOut> extends $ZodTypeDef {
1059
1059
  type: "function";
1060
1060
  input: In;
@@ -1054,7 +1054,7 @@ export type $ZodFunctionOut = $ZodType;
1054
1054
  export type $InferInnerFunctionType<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (...args: $ZodFunctionIn extends Args ? never[] : core.output<Args>) => core.input<Returns>;
1055
1055
  export type $InferInnerFunctionTypeAsync<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (...args: $ZodFunctionIn extends Args ? never[] : core.output<Args>) => util.MaybeAsync<core.input<Returns>>;
1056
1056
  export type $InferOuterFunctionType<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (...args: $ZodFunctionIn extends Args ? never[] : core.input<Args>) => core.output<Returns>;
1057
- export type $InferOuterFunctionTypeAsync<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (...args: $ZodFunctionIn extends Args ? never[] : core.input<Args>) => util.MaybeAsync<core.output<Returns>>;
1057
+ export type $InferOuterFunctionTypeAsync<Args extends $ZodFunctionIn, Returns extends $ZodFunctionOut> = (...args: $ZodFunctionIn extends Args ? never[] : core.input<Args>) => Promise<core.output<Returns>>;
1058
1058
  export interface $ZodFunctionDef<In extends $ZodFunctionIn = $ZodFunctionIn, Out extends $ZodFunctionOut = $ZodFunctionOut> extends $ZodTypeDef {
1059
1059
  type: "function";
1060
1060
  input: In;