Skip to content

Commit 76d3fed

Browse files
committed
Rename MappedObjectSchema -> LiteralObjectSchema
1 parent d3fcb32 commit 76d3fed

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/factory.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import {
55
BooleanSchema,
66
CustomSchema,
77
DateSchema,
8-
MappedObjectKeySchemas,
9-
MappedObjectSchema,
8+
LiteralObjectKeySchemas,
9+
LiteralObjectSchema,
1010
NumberSchema,
1111
ObjectSchema,
1212
OrSchema,
@@ -68,15 +68,15 @@ export function value<T extends string | number | boolean | null | undefined>(va
6868
* @param fields The object and nested validation schemas the value must match.
6969
* @param requiredMessage The error to return if the value is undefined.
7070
*/
71-
export function object<T>(fields: MappedObjectKeySchemas<T>, requiredMessage?: string): MappedObjectSchema<T>;
71+
export function object<T>(fields: LiteralObjectKeySchemas<T>, requiredMessage?: string): LiteralObjectSchema<T>;
7272
/**
7373
* Requires this field to be a object, allowing all keys and values.
7474
* @param requiredMessage The error to return if the value is undefined.
7575
*/
7676
export function object<T>(requiredMessage?: string): ObjectSchema;
7777
export function object() {
7878
if (typeof arguments[0] === "object") {
79-
return new MappedObjectSchema(arguments[0], arguments[1]);
79+
return new LiteralObjectSchema(arguments[0], arguments[1]);
8080
} else {
8181
return new ObjectSchema(arguments[0] ?? arguments[1]);
8282
}
@@ -143,6 +143,11 @@ export function any(requiredMessage?: string) {
143143
return new AnySchema(requiredMessage);
144144
}
145145

146+
/**
147+
* Requires this field to be a mapped object type.
148+
* @param keySchema The keys of the object must match this schema.
149+
* @param valueSchema The values of the object must match this schema.
150+
*/
146151
export function mapped<K extends string | number | symbol, V>(keySchema: Schema<K>, valueSchema: Schema<V>): MappedSchema<K, V> {
147152
return new MappedSchema(keySchema, valueSchema);
148153
}

src/schemas.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ export class ObjectSchema extends Schema<object> {
343343
}
344344
}
345345

346-
export type MappedObjectKeySchemas<T> = {
346+
export type LiteralObjectKeySchemas<T> = {
347347
[Key in keyof T]: Schema<T[Key]>;
348348
};
349349

@@ -358,8 +358,8 @@ type MergeIntersection<T> = {
358358
[Key in keyof T]: T[Key];
359359
};
360360

361-
export class MappedObjectSchema<T extends {}> extends Schema<MergeIntersection<MakeUndefinedOptional<T>>> {
362-
public constructor(protected fields: MappedObjectKeySchemas<T>, requiredMessage?: string) {
361+
export class LiteralObjectSchema<T extends {}> extends Schema<MergeIntersection<MakeUndefinedOptional<T>>> {
362+
public constructor(protected fields: LiteralObjectKeySchemas<T>, requiredMessage?: string) {
363363
super(requiredMessage);
364364
}
365365

0 commit comments

Comments
 (0)