Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
colinhacks committed Mar 21, 2024
1 parent d1daf10 commit fce504f
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 28 deletions.
4 changes: 2 additions & 2 deletions deno/lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<T extends z.ZodTypeAny>(schema: T) {
Expand Down Expand Up @@ -2747,7 +2747,7 @@ Due to how TypeScript inference works, it is treating `schema` like a `ZodTypeAn
```ts
function parseData<T extends z.ZodTypeAny>(data: unknown, schema: T) {
return schema.parse(data) as z.infer<T>;
// ^^^^^^^^^^^^^^ <- add this
// ^^^^^^^^^^^^^^ <- add this
}

parseData("sup", z.string());
Expand Down
17 changes: 8 additions & 9 deletions deno/lib/__tests__/preprocess.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 0 additions & 3 deletions deno/lib/__tests__/transformer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,6 @@ test("multiple transformers", () => {
expect(doubler.parse("5")).toEqual(10);
});



test("short circuit on dirty", () => {
const schema = z
.string()
Expand All @@ -217,7 +215,6 @@ test("short circuit on dirty", () => {
}
});


test("async short circuit on dirty", async () => {
const schema = z
.string()
Expand Down
2 changes: 1 addition & 1 deletion deno/lib/helpers/parseUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export const isAborted = (x: ParseReturnType<any>): x is INVALID =>
(x as any).status === "aborted";
export const isDirty = <T>(x: ParseReturnType<T>): x is OK<T> | DIRTY<T> =>
(x as any).status === "dirty";
export const isValid = <T>(x: ParseReturnType<T>): x is OK<T> =>
export const isValid = <T>(x: ParseReturnType<T>): x is OK<T> =>
(x as any).status === "valid";
export const isAsync = <T>(
x: ParseReturnType<T>
Expand Down
17 changes: 8 additions & 9 deletions src/__tests__/preprocess.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 0 additions & 3 deletions src/__tests__/transformer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,6 @@ test("multiple transformers", () => {
expect(doubler.parse("5")).toEqual(10);
});



test("short circuit on dirty", () => {
const schema = z
.string()
Expand All @@ -216,7 +214,6 @@ test("short circuit on dirty", () => {
}
});


test("async short circuit on dirty", async () => {
const schema = z
.string()
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/parseUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export const isAborted = (x: ParseReturnType<any>): x is INVALID =>
(x as any).status === "aborted";
export const isDirty = <T>(x: ParseReturnType<T>): x is OK<T> | DIRTY<T> =>
(x as any).status === "dirty";
export const isValid = <T>(x: ParseReturnType<T>): x is OK<T> =>
export const isValid = <T>(x: ParseReturnType<T>): x is OK<T> =>
(x as any).status === "valid";
export const isAsync = <T>(
x: ParseReturnType<T>
Expand Down

0 comments on commit fce504f

Please sign in to comment.