Releases: nvie/decoders
v1.16.1
v1.16.0
v1.15.0
New features:
- Support constructors that have required arguments in
instanceOf
decoders in TypeScript (see #308, thanks @Jessidhia!) - Add support for type predicates in
predicate()
in TypeScript (see #310, thanks @Jessidhia!)
Fixes:
- Add support for Flow >= 0.101.0
v1.14.0
v1.13.1
v1.13.0
Potentially breaking changes:
-
Changed the API interface of
dispatch()
. The previous version was too complicated and was hardly used. The new version is easier to use in practice, and has better type inference support in TypeScript and Flow.Previous usage:
const shape = dispatch( field('type', string), type => { switch (type) { case 'rect': return rectangle; case 'circle': return circle; } return fail('Must be a valid shape'); } );
New usage: docs
const shape = dispatch('type', { rectangle, circle });
Where
rectangle
andcircle
are decoders of which exactly one will be invoked.
-
Removed the
field()
decoder. It was not generic enough to stay part of the standard decoder library. (It was typically used in combination withdispatch()
, which now isn't needed anymore, see above.) -
pojo
decoder now returnsDecoder<{[string]: mixed}>
instead of the unsafeDecoder<Object>
.
Fixes and cleanup:
- Internal reorganization of modules
- Improve TypeScript support
- Reorganization of TypeScript declarations
- More robust test suite for TypeScript
- 100% TypeScript test coverage
v1.12.0
v1.11.1
v1.11.0
Potentially breaking changes:
- Decoders now all take
mixed
(TypeScript:unknown
) arguments, instead of
any
🎉 ! This ensures that the proper type refinements in the
implementation of your decoder are made. (See migration notes below.) - Invalid dates (e.g.
new Date('not a date')
) won’t be considered valid by
thedate
decoder anymore.
New features:
-
guard()
now takes a config option to control how to format error
messages. This is done via theguard(..., { style: 'inline' })
parameter.'inline'
: echoes back the input value and inlines errors (default);'simple'
: just returns the decoder errors. Useful for use in sensitive contexts.
-
Export
$DecoderType
utility type so it can be used outside of the decoders
library.
Fixes:
- Fixes for some TypeScript type definitions.
- Add missing documentation.
Migration notes:
If your decoder code breaks after upgrading to 1.11.0, please take the
following measures to upgrade:
-
If you wrote any custom decoders of this form yourself:
const mydecoder = (blob: any) => ... // ^^^ Decoder function taking `any`
You should now convert those to:
const mydecoder = (blob: mixed) => ... // ^^^^^ Decoders should take `mixed` from now on
Or, for TypeScript:
const mydecoder = (blob: unknown) => ... // ^^^^^^^ `unknown` for TypeScript
Then follow and fix type errors that pop up because you were making
assumptions that are now caught by the type checker. -
If you wrote any decoders based on
predicate()
, you may have code like
this:const mydecoder: Decoder<string> = predicate( s => s.startsWith('x'), 'Must start with "x"' );
You'll have to change the explicit Decoder type of those to take two type
arguments:const mydecoder: Decoder<string, string> = predicate( // ^^^^^^ Provide the input type to predicate() decoders s => s.startsWith('x'), 'Must start with "x"' );
This now explicitly records that
predicate()
makes assumptions about its
input type—previously this wasn’t get caught correctly.
v1.11.0-alpha2
v1.11.0-alpha2