UNPKG

bookish-potato-dto

Version:

A TypeScript DTO (Data Transfer Object) parsing and validation library. Define a schema once — get runtime validation and a fully inferred TypeScript type for free.

35 lines (34 loc) 1.56 kB
export interface PropertyData<T> { /** * The default value for the property to be used if no value is provided. */ readonly defaultValue?: T | null; /** * Defines if the property is optional. If true, the property can be omitted. * By default, properties are required. * If a property is optional, the property will be set to the defaultValue. * @deprecated Since options cannot reflect the data type, this option is deprecated. * Use <code>.optional()</code> instead. Example: <code>field.string().optional()</code> */ readonly isOptional?: boolean; /** * Defines if the property can be null. * @deprecated Since options cannot reflect the data type, this option is deprecated. * Use <code>.nullable()</code> instead. Example: <code>field.string().nullable()</code> */ readonly isNullable?: boolean; /** * Defines if the property should be set to the default value if the value is not parsable. * By default, the property will throw an error if the value is not parsable. */ readonly useDefaultValueOnParseError?: boolean; /** * Defines the key in the provided object from which the property should be mapped. * By default, the property will be mapped from the key with the same name as the property. */ readonly mapFrom?: string; /** * Defines the custom error message to use when the property cannot be parsed. */ readonly parsingErrorMessage?: (key: string, valueToParse: unknown, causedBy: unknown) => string; }