Skip to content

Commit

Permalink
Add types to ZodFirstPartySchemaTypes (#3247)
Browse files Browse the repository at this point in the history
* Add `ZodSymbol` and `ZodReadonly` to  `ZodFirstPartySchemaTypes`

* Test `ZodFirstPartySchemaTypes` in sync with `ZodFirstPartyTypeKind`
  • Loading branch information
MatthijsMud authored Mar 14, 2024
1 parent 7fa37bb commit cb94d30
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/__tests__/firstpartyschematypes.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// @ts-ignore TS6133
import { test } from "@jest/globals";
import { util } from "../helpers/util";

import {
ZodFirstPartySchemaTypes,
ZodFirstPartyTypeKind,
} from "..";

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.assertNever({} as ZodFirstPartySchemaTypesMissingFromUnion);
});
4 changes: 3 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4972,7 +4972,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

0 comments on commit cb94d30

Please sign in to comment.