Schema.validate()method
Validate an unknown input value and return a known, valid value of type T.
validate(unsafeValue: unknown): T
new Schema<T>({ one = "value", many = `${one}s`, title, description, placeholder, value }: SchemaOptions)| Param | Type | |
|---|---|---|
options | SchemaOptions | Options allowed by a Schema instance. required |
.one | string | String for one of this thing, e.g. product or item or sheep readonly |
.many | string | String for several of this thing, e.g. products or items or sheep (defaults to one + "s") readonly |
.title | string | Title of the schema, e.g. for using as the title of a corresponding field. readonly |
.description | string | Description of the schema, e.g. for using as a description in a corresponding field. readonly |
.placeholder | string | Placeholder of the schema, e.g. for using as a placeholder in a corresponding field. readonly |
.value | unknown | 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. |
| Property | Type | |
|---|---|---|
.one | string | String for one of this thing, e.g. product or item or sheep required readonly |
.many | string | String for several of this thing, e.g. products or items or sheep (defaults to one + "s") required readonly |
.title | string | Title of the schema, e.g. for using as the title of a corresponding field. readonly |
.description | string | Description of the schema, e.g. for using as a description in a corresponding field. readonly |
.placeholder | string | Placeholder of the schema, e.g. for using as a placeholder in a corresponding field. readonly |
.value | unknown | 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.
T represents the type of value validate() returns.validate() throws a string error message if the value was not valid.class CustomSchema extends Schema<string> {
validate(unsafeValue: unknown): string {
if (typeof unsafeValue !== "string") throw "Must be string";
return unsafeValue;
}
}Validate an unknown input value and return a known, valid value of type T.
validate(unsafeValue: unknown): T
Format a validated value of this type as a string for display.
format(value: T): string