๐Ÿ“ฆ colinhacks / zod-deno

๐Ÿ“„ firstpartyschematypes.test.ts ยท 26 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26// @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);
});