-
Add support for the new TypeScript compiler option
exactOptionalPropertyTypes
. This adds a new construct:ObjWithOptional
which mark properties from its second argument as optional in the TypeScript sense. So you getprop?: type
for them instead ofprop: type | undefined
orprop: type
.Optional
is renamed toMaybeUndefined
to avoid confusion.Here is an example of the new
ObjWithOptional
:ObjWithOptional({ a: NUMBER, }, { b: STRING }) // This schema will typecheck values as: { a: number, b?: string } // If you want b to possibly be undefined you can do instead: ObjWithOptional({ a: NUMBER, }, { b: MaybeUndefined(STRING) }) // This will typecheck values as: { a: number, b?: string | undefined }
Note that this only works when the new flag is set to true. If the flag is set to false or if you use an older version of TypeScript then in both case the type will be:
{ a: number, b?: string | undefined }
typesafe-schema
does not look whether the flag is set to true or not. This means that even though the compiler won't differentiate between the two cases this library will.
- Add
MinLength
helper to require a field to have a minimum length. Supported type areSTRING
,Arr(..)
andDict(..)
.
- Augment type limit for Enum and EnumObj to accept up to 8 values
- Render null as 'null'
No API changes
- Add support for dictionaries: arbitrary keys with a validated type.
- Add
TRUE
andFALSE
constant to allow narrowing a type with boolean values
- Fix a bug when an
Obj
is expected but a string is provided to thevalidate
function. Error wasTypeError: Cannot use 'in' operator to search for 'message' in "Not found"
;
- Remove coverage report from the npm package.
- Export
ValidationSuccess
,ValidationError
andValidationResult
types.
- Instead of a function we now return an object with two properties:
validator.validate()
: A function that can validate objects.validator.schema
: The original schema used by the validate function.
- Version 0.2 was fundamentaly broken, this release fix a number of issues:
- Possibility to constraint the resulting type
- Default it to TypeOf
- Add a test to make sure this is not broken in the future.
- Bug fix. Missing
TypeOf
in export.
- Bug fix. Missing
Any
in export.
- Add a
strict
argument to validators that reject value that have extra properties.
- Add a
schema
field to validators to reduce boilerplate when using composition - Rename
defineSchema
tonewValidator
, the original name was confusing
Initial release.