Schemaclass

new Schema<T>({ one = "value", many = `${one}s`, title, description, placeholder, value }: SchemaOptions)
ParamType
optionsSchemaOptions
Options allowed by a Schema instance. required
    .onestring
String for one of this thing, e.g. product or item or sheep readonly
    .manystring
String for several of this thing, e.g. products or items or sheep (defaults to one + "s") readonly
    .titlestring
Title of the schema, e.g. for using as the title of a corresponding field. readonly
    .descriptionstring
Description of the schema, e.g. for using as a description in a corresponding field. readonly
    .placeholderstring
Placeholder of the schema, e.g. for using as a placeholder in a corresponding field. readonly
    .valueunknown
Default value for the schema if validate() is called with an undefined value. readonly
Return
Schema<T>
Schema is an object instance with a validate() method that converts unknown input into a known, valid type T.
PropertyType
.onestring
String for one of this thing, e.g. product or item or sheep required readonly
.manystring
String for several of this thing, e.g. products or items or sheep (defaults to one + "s") required readonly
.titlestring
Title of the schema, e.g. for using as the title of a corresponding field. readonly
.descriptionstring
Description of the schema, e.g. for using as a description in a corresponding field. readonly
.placeholderstring
Placeholder of the schema, e.g. for using as a placeholder in a corresponding field. readonly
.valueunknown
Default value for the schema if validate() is called with an undefined value. required readonly

Schema is an object instance with a validate() method that converts unknown input into a known, valid type T.

  • Type T represents the type of value validate() returns.
  • validate() throws a string error message if the value was not valid.

Examples

class CustomSchema extends Schema<string> {
 	validate(unsafeValue: unknown): string {
 		if (typeof unsafeValue !== "string") throw "Must be string";
 		return unsafeValue;
 	}
 }

Methods

Go

Schema.validate()method

Validate an unknown input value and return a known, valid value of type T.

validate(unsafeValue: unknown): T
Go

Schema.format()method

Format a validated value of this type as a string for display.

format(value: T): string