The old Dictionary signature remains, but is deprecated.
Removed top level match helper
It was too difficult to ensure TypeScript inferred the correct types, and you can do the same thing using the match method on a Union.
Before:
const f = match(
[Literal(42), fortyTwo => fortyTwo / 2],
[Number, n => n + 9],
[String, s => s.length * 2],
);
f(42) // => 21
After:
const f = Union(Literal(42), Number, String).match(
fortyTwo => fortyTwo / 2,
n => n + 9,
s => s.length * 2,
);
f(42) // => 21
All properties of the Runtype validators are now marked as readonly
Lazy types are now a proper type of runtype with an explicit tag and underlying method
This only impacts you if you were manually performing Reflection, or if you expected Lazy(() => Object({v: Foo})) to be an actual Object type rather than just a Runtype<{v: Foo}>
Change Log for funtypes (1.0.0 → 2.0.0)
Breaking Changes
AsyncContract
andContract
now allow arbitrary numbers of parametersIn order to simplify the API and support an arbitrarily long list of parameters, the API now expects the parameter types as an Array.
Before:
After:
Renamed
Dictionary
toRecord
and made parameters match up with TypeScriptRecord
This allows you to specify additional constraints on keys, beyond simply
number
orstring
.Before:
After:
The old Dictionary signature remains, but is deprecated.
Removed top level
match
helperIt was too difficult to ensure TypeScript inferred the correct types, and you can do the same thing using the
match
method on aUnion
.Before:
After:
All properties of the Runtype validators are now marked as
readonly
Lazy
types are now a proper type of runtype with an explicit tag andunderlying
methodThis only impacts you if you were manually performing Reflection, or if you expected
Lazy(() => Object({v: Foo}))
to be an actualObject
type rather than just aRuntype<{v: Foo}>
Array
andReadonlyArray
are now separate typesBefore:
After:
All validation errors in
AsyncContract
are now returned as rejected promisesThis is much more consistent, and prevents you from having to separately handle synchronous errors and asynchronous errors.
New Features
Unions of objects and tuples now produce better errors
<tag: value>
to indicate which path was taken on discriminated unionsLiteral
as their first componentEdit changelog