Skip to content

Commit

Permalink
Adds getters to Map for key + value
Browse files Browse the repository at this point in the history
  • Loading branch information
bbar committed Apr 20, 2023
1 parent 502384e commit cc0a9fe
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
7 changes: 4 additions & 3 deletions deno/lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
- [Coercion for primitives](#coercion-for-primitives)
- [Literals](#literals)
- [Strings](#strings)
- [Datetime](#datetime-validation)
- [IP](#ip-address-validation)
- [Datetime](#iso-datetimes)
- [IP](#ip-addresses)
- [Numbers](#numbers)
- [BigInts](#bigints)
- [NaNs](#nans)
Expand Down Expand Up @@ -431,6 +431,7 @@ There are a growing number of tools that are built atop or support Zod natively!
- [`@modular-forms/solid`](https://github.com/fabian-hiller/modular-forms): Modular form library for SolidJS that supports Zod for validation.
- [`houseform`](https://github.com/crutchcorn/houseform/): A React form library that uses Zod for validation.
- [`sveltekit-superforms`](https://github.com/ciscoheat/sveltekit-superforms): Supercharged form library for SvelteKit with Zod validation.
- [`mobx-zod-form`](https://github.com/MonoidDev/mobx-zod-form): Data-first form builder based on MobX & Zod

#### Zod to X

Expand Down Expand Up @@ -623,7 +624,7 @@ z.coerce.boolean().parse(null); // => false

## Literals

Literal schemas represent a [literal type](https://www.typescriptlang.org/docs/handbook/literal-types.html), like `"hello world"` or `5`.
Literal schemas represent a [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types), like `"hello world"` or `5`.

```ts
const tuna = z.literal("tuna");
Expand Down
6 changes: 6 additions & 0 deletions deno/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3431,6 +3431,12 @@ export class ZodMap<
ZodMapDef<Key, Value>,
Map<Key["_input"], Value["_input"]>
> {
get keySchema() {
return this._def.keyType;
}
get valueSchema() {
return this._def.valueType;
}
_parse(input: ParseInput): ParseReturnType<this["_output"]> {
const { status, ctx } = this._processInputParams(input);
if (ctx.parsedType !== ZodParsedType.map) {
Expand Down
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3431,6 +3431,12 @@ export class ZodMap<
ZodMapDef<Key, Value>,
Map<Key["_input"], Value["_input"]>
> {
get keySchema() {
return this._def.keyType;
}
get valueSchema() {
return this._def.valueType;
}
_parse(input: ParseInput): ParseReturnType<this["_output"]> {
const { status, ctx } = this._processInputParams(input);
if (ctx.parsedType !== ZodParsedType.map) {
Expand Down

0 comments on commit cc0a9fe

Please sign in to comment.