Skip to content

Commit

Permalink
Added new tests for covariance on the output and contravariance on th…
Browse files Browse the repository at this point in the history
…e input
  • Loading branch information
mstniy committed Oct 12, 2024
1 parent f9ca8b0 commit 304c024
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions deno/lib/__tests__/type.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,17 @@ import * as z from "../index.ts";
test("ZodType is covariant with the output", () => {
function f<S extends z.ZodType<string, any, any>>(_: S) {}
f(z.literal("a"));

function g<S extends z.ZodType<"a", any, any>>(_: S) {}
// @ts-expect-error
g(z.string());
});

test("ZodType is contravariant with the input", () => {
function f<S extends z.ZodType<any, any, "a">>(_: S) {}
f(z.string());

function g<S extends z.ZodType<any, any, string>>(_: S) {}
// @ts-expect-error
g(z.literal("a"));
});
21 changes: 21 additions & 0 deletions src/__tests__/type.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { test } from "@jest/globals";

import * as z from "../index";

test("ZodType is covariant with the output", () => {
function f<S extends z.ZodType<string, any, any>>(_: S) {}
f(z.literal("a"));

function g<S extends z.ZodType<"a", any, any>>(_: S) {}
// @ts-expect-error
g(z.string());
});

test("ZodType is contravariant with the input", () => {
function f<S extends z.ZodType<any, any, "a">>(_: S) {}
f(z.string());

function g<S extends z.ZodType<any, any, string>>(_: S) {}
// @ts-expect-error
g(z.literal("a"));
});

0 comments on commit 304c024

Please sign in to comment.