- add
nonStrict
combinator (#90)nonStrict
creates a non-strictrecord
runtype from a providedrecord
runtype- a non-strict
record
runtype will ignore keys that are not specified in the original runtype's typemap
- add
isRuntypeError
predicate to write type-safe try-catch blocks - remove
sloppyRecord
- replaced by
nonStrict
:sloppyRecord(X)
->nonStrict(record(X))
- fixes #23
- replaced by
- fix: allow literal booleans as type-discriminators in discriminated unions, see #98
- fix:
string
trim & maxlength checks: #100 - fix:
record
optionals: #100
- fix: invalid key message was displaying the object instead of the keys, see #91
- fix:
json
now keeps the type information from the passed runtype
- fix: make
sloppyRecord
impure (closes #60)
- add
json
runtype - add
minLength
option tostring
runtype
- rename
nullable
tonullOr
to be consistent withundefinedOr
(because undefinable is not a good name) - add
undefinedOr
that works like the oldoptional
type - real optional keys in
record
s: Changeoptional
to be only usable inrecord
. Using it will result in the key to be infered as optional:record({key: optional(number())})
results in{key?: number}
as the type (old behavior would infer{key: undefined | number}
, you can get the old behaviour by usingundefinedOr
instead ofoptional
) - add
dictionary
and removenumberIndex
andstringIndex
Usedictionary(stringAsInteger(), otherType)
to replacenumberIndex
anddictionary(string(), otherType)
to replacestringIndex
.
- add
partial
combinator runtype
- add
match
option tostring
to test the string against a regular expression
- fix and improve error value and path formatting (shout outs to @pabra for the patch)
- support intersection of unions and records
- fix: rename
useRuntype
touse
- change
useRuntype
to return aValidationResult
to support using runtypes without relying on exceptions and win in benchmarks - rename
fail
tocreateError
- make
isFail
private, useValidationResult.ok
instead
- fix
fail
to not returnany
butFail
Now, custom runtypes will result in the correct inferred type ofRuntype<T>
instead ofRuntype<any>
for custom runtypes that might return a failure.
- fix missing error utility (
getFormattedError()
, ...) exports
- add
useRuntype
to call other runtypes in custom runtypes - rename
enumValue
toenum
- remove
discriminatedUnion
- use the normalunion
instead. The discriminantkey
gets inferrred automatically byunion
now.
- fix error messages
- add
sloppyRecord
(props to @pabra) - add
undefined
andnull
runtypes (props to @pabra)
- fix broken runtypes for
string
andinteger
due to missing return type annotations
- use copy-on-write for performance: they mostly just check their input object and return it unmodified. Before that, arrays and objects were always copied. Now, only if the runtype or any nested runtype modifies its input (e.g. trimming strings or custom runtypes), objects and arrays are copied.
stringIndex
andnumberIndex
now err on"__proto__"
andSymbol
keys
- add explicit options (min, max, length etc.) to
string
,number
,integer
,stringAsInteger
andarray
runtypes - change error messages
- improve
stringAsInteger
to accept'-0'
and'+123'
(leading plus) as valid integer strings
- remove
.check
and make user invocations of runtypes throw exceptions (using.check
turned out to be a major annoyance and I forgot it in almost half of my code bc typescript does not warn me) - add
runtype
to create custom runtypes - add
RuntypeUsageError
, thrown when the api is misused - add
getFormattedError
,getFormattedErrorPath
andgetFormattedErrorValue
functions to extract information fromRuntypeError
- add
.check
method throw aRuntypeException
- add
fail
,isFail
to replace throwingRuntypeException
on runtype errors - add
union
, make intersection universal for all runtypes - add
pick
andomit
combinators