Skip to content

Commit

Permalink
Make EnumValues generic (#2338)
Browse files Browse the repository at this point in the history
* feat: make EnumValues generic

Allow statically validate enum values against external type.
Fix #2280.

* Docs

---------

Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>
  • Loading branch information
IlyaSemenov and colinhacks authored Apr 9, 2024
1 parent 69eee9c commit 8b723d4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions deno/lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
- [Coercion for primitives](#coercion-for-primitives)
- [Literals](#literals)
- [Strings](#strings)
- [ISO datetimes](#iso-datetimes)
- [IP addresses](#ip-addresses)
- [Datetime](#iso-datetimes)
- [IP](#ip-addresses)
- [Numbers](#numbers)
- [BigInts](#bigints)
- [NaNs](#nans)
Expand Down
2 changes: 1 addition & 1 deletion deno/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4081,7 +4081,7 @@ export class ZodLiteral<T> extends ZodType<T, ZodLiteralDef<T>> {
export type ArrayKeys = keyof any[];
export type Indices<T> = Exclude<keyof T, ArrayKeys>;

export type EnumValues = [string, ...string[]];
export type EnumValues<T extends string = string> = [T, ...T[]];

export type Values<T extends EnumValues> = {
[k in T[number]]: k;
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4081,7 +4081,7 @@ export class ZodLiteral<T> extends ZodType<T, ZodLiteralDef<T>> {
export type ArrayKeys = keyof any[];
export type Indices<T> = Exclude<keyof T, ArrayKeys>;

export type EnumValues = [string, ...string[]];
export type EnumValues<T extends string = string> = [T, ...T[]];

export type Values<T extends EnumValues> = {
[k in T[number]]: k;
Expand Down

0 comments on commit 8b723d4

Please sign in to comment.