diff --git a/deno/lib/README.md b/deno/lib/README.md index 469ebb8ad..0bb2a4ef3 100644 --- a/deno/lib/README.md +++ b/deno/lib/README.md @@ -2714,7 +2714,7 @@ inferSchema(z.string()); This approach loses type information, namely _which subclass_ the input actually is (in this case, `ZodString`). That means you can't call any string-specific methods like `.min()` on the result of `inferSchema`. -A better approach is to infer _the schema as a whole_ instead of merely it's inferred type. You can do this with a utility type called `z.ZodTypeAny`. +A better approach is to infer _the schema as a whole_ instead of merely its inferred type. You can do this with a utility type called `z.ZodTypeAny`. ```ts function inferSchema(schema: T) { @@ -2747,7 +2747,7 @@ Due to how TypeScript inference works, it is treating `schema` like a `ZodTypeAn ```ts function parseData(data: unknown, schema: T) { return schema.parse(data) as z.infer; - // ^^^^^^^^^^^^^^ <- add this + // ^^^^^^^^^^^^^^ <- add this } parseData("sup", z.string()); diff --git a/deno/lib/__tests__/preprocess.test.ts b/deno/lib/__tests__/preprocess.test.ts index 63549142c..50ac02e05 100644 --- a/deno/lib/__tests__/preprocess.test.ts +++ b/deno/lib/__tests__/preprocess.test.ts @@ -45,32 +45,31 @@ test("preprocess ctx.addIssue with parse", () => { }); test("preprocess ctx.addIssue non-fatal by default", () => { - - try{ - z.preprocess((data, ctx) => { + try { + z.preprocess((data, ctx) => { ctx.addIssue({ code: "custom", message: `custom error`, }); return data; }, z.string()).parse(1234); - }catch(err){ + } catch (err) { z.ZodError.assert(err); expect(err.issues.length).toEqual(2); } -}) +}); test("preprocess ctx.addIssue fatal true", () => { - try{ - z.preprocess((data, ctx) => { + try { + z.preprocess((data, ctx) => { ctx.addIssue({ code: "custom", message: `custom error`, - fatal: true + fatal: true, }); return data; }, z.string()).parse(1234); - }catch(err){ + } catch (err) { z.ZodError.assert(err); expect(err.issues.length).toEqual(1); } diff --git a/deno/lib/__tests__/transformer.test.ts b/deno/lib/__tests__/transformer.test.ts index d49202473..108b12e91 100644 --- a/deno/lib/__tests__/transformer.test.ts +++ b/deno/lib/__tests__/transformer.test.ts @@ -197,8 +197,6 @@ test("multiple transformers", () => { expect(doubler.parse("5")).toEqual(10); }); - - test("short circuit on dirty", () => { const schema = z .string() @@ -217,7 +215,6 @@ test("short circuit on dirty", () => { } }); - test("async short circuit on dirty", async () => { const schema = z .string() diff --git a/deno/lib/helpers/parseUtil.ts b/deno/lib/helpers/parseUtil.ts index d0caf80eb..8df221464 100644 --- a/deno/lib/helpers/parseUtil.ts +++ b/deno/lib/helpers/parseUtil.ts @@ -173,7 +173,7 @@ export const isAborted = (x: ParseReturnType): x is INVALID => (x as any).status === "aborted"; export const isDirty = (x: ParseReturnType): x is OK | DIRTY => (x as any).status === "dirty"; -export const isValid = (x: ParseReturnType): x is OK => +export const isValid = (x: ParseReturnType): x is OK => (x as any).status === "valid"; export const isAsync = ( x: ParseReturnType diff --git a/src/__tests__/preprocess.test.ts b/src/__tests__/preprocess.test.ts index 9e4cac77e..271d293ae 100644 --- a/src/__tests__/preprocess.test.ts +++ b/src/__tests__/preprocess.test.ts @@ -44,32 +44,31 @@ test("preprocess ctx.addIssue with parse", () => { }); test("preprocess ctx.addIssue non-fatal by default", () => { - - try{ - z.preprocess((data, ctx) => { + try { + z.preprocess((data, ctx) => { ctx.addIssue({ code: "custom", message: `custom error`, }); return data; }, z.string()).parse(1234); - }catch(err){ + } catch (err) { z.ZodError.assert(err); expect(err.issues.length).toEqual(2); } -}) +}); test("preprocess ctx.addIssue fatal true", () => { - try{ - z.preprocess((data, ctx) => { + try { + z.preprocess((data, ctx) => { ctx.addIssue({ code: "custom", message: `custom error`, - fatal: true + fatal: true, }); return data; }, z.string()).parse(1234); - }catch(err){ + } catch (err) { z.ZodError.assert(err); expect(err.issues.length).toEqual(1); } diff --git a/src/__tests__/transformer.test.ts b/src/__tests__/transformer.test.ts index 75f88da94..0f80aa030 100644 --- a/src/__tests__/transformer.test.ts +++ b/src/__tests__/transformer.test.ts @@ -196,8 +196,6 @@ test("multiple transformers", () => { expect(doubler.parse("5")).toEqual(10); }); - - test("short circuit on dirty", () => { const schema = z .string() @@ -216,7 +214,6 @@ test("short circuit on dirty", () => { } }); - test("async short circuit on dirty", async () => { const schema = z .string() diff --git a/src/helpers/parseUtil.ts b/src/helpers/parseUtil.ts index 687ed118b..4824fcf7f 100644 --- a/src/helpers/parseUtil.ts +++ b/src/helpers/parseUtil.ts @@ -173,7 +173,7 @@ export const isAborted = (x: ParseReturnType): x is INVALID => (x as any).status === "aborted"; export const isDirty = (x: ParseReturnType): x is OK | DIRTY => (x as any).status === "dirty"; -export const isValid = (x: ParseReturnType): x is OK => +export const isValid = (x: ParseReturnType): x is OK => (x as any).status === "valid"; export const isAsync = ( x: ParseReturnType