Skip to content

Commit

Permalink
Fix firstparty tests
Browse files Browse the repository at this point in the history
  • Loading branch information
colinhacks committed Mar 14, 2024
1 parent 0f3811f commit 0575b65
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
4 changes: 4 additions & 0 deletions deno/lib/__tests__/firstparty.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ test("first party switch", () => {
break;
case z.ZodFirstPartyTypeKind.ZodPipeline:
break;
case z.ZodFirstPartyTypeKind.ZodSymbol:
break;
case z.ZodFirstPartyTypeKind.ZodReadonly:
break;
default:
util.assertNever(def);
}
Expand Down
21 changes: 21 additions & 0 deletions deno/lib/__tests__/firstpartyschematypes.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// @ts-ignore TS6133
import { expect } from "https://deno.land/x/expect@v0.2.6/mod.ts";
const test = Deno.test;

import {
ZodFirstPartySchemaTypes,
ZodFirstPartyTypeKind,
} from "../index.ts";
import { util } from "../helpers/util.ts";

test("Identify missing [ZodFirstPartySchemaTypes]", () => {
type ZodFirstPartySchemaForType<T extends ZodFirstPartyTypeKind> = ZodFirstPartySchemaTypes extends infer Schema
? Schema extends { _def: { typeName: T } }
? Schema
: never
: never;
type ZodMappedTypes = { [key in ZodFirstPartyTypeKind]: ZodFirstPartySchemaForType<key> };
type ZodFirstPartySchemaTypesMissingFromUnion = keyof { [key in keyof ZodMappedTypes as ZodMappedTypes[key] extends { _def: never } ? key : never]: unknown };

util.assertEqual<ZodFirstPartySchemaTypesMissingFromUnion, never>(true);
});
4 changes: 3 additions & 1 deletion deno/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4978,7 +4978,9 @@ export type ZodFirstPartySchemaTypes =
| ZodCatch<any>
| ZodPromise<any>
| ZodBranded<any, any>
| ZodPipeline<any, any>;
| ZodPipeline<any, any>
| ZodReadonly<any>
| ZodSymbol;

// requires TS 4.4+
abstract class Class {
Expand Down
4 changes: 4 additions & 0 deletions src/__tests__/firstparty.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ test("first party switch", () => {
break;
case z.ZodFirstPartyTypeKind.ZodPipeline:
break;
case z.ZodFirstPartyTypeKind.ZodSymbol:
break;
case z.ZodFirstPartyTypeKind.ZodReadonly:
break;
default:
util.assertNever(def);
}
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/firstpartyschematypes.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// @ts-ignore TS6133
import { test } from "@jest/globals";
import { util } from "../helpers/util";

import {
ZodFirstPartySchemaTypes,
ZodFirstPartyTypeKind,
} from "..";
import { util } from "../helpers/util";

test("Identify missing [ZodFirstPartySchemaTypes]", () => {
type ZodFirstPartySchemaForType<T extends ZodFirstPartyTypeKind> = ZodFirstPartySchemaTypes extends infer Schema
Expand All @@ -16,5 +16,5 @@ test("Identify missing [ZodFirstPartySchemaTypes]", () => {
type ZodMappedTypes = { [key in ZodFirstPartyTypeKind]: ZodFirstPartySchemaForType<key> };
type ZodFirstPartySchemaTypesMissingFromUnion = keyof { [key in keyof ZodMappedTypes as ZodMappedTypes[key] extends { _def: never } ? key : never]: unknown };

util.assertNever({} as ZodFirstPartySchemaTypesMissingFromUnion);
});
util.assertEqual<ZodFirstPartySchemaTypesMissingFromUnion, never>(true);
});

0 comments on commit 0575b65

Please sign in to comment.