Decoder that makes a field optional.
The decoder for the field when it is present
A decoder that accepts either the decoded value or undefined
interface User { name: string; age?: number;}const userDecoder = JsonDecoder.object<User>( { name: JsonDecoder.string(), age: JsonDecoder.optional(JsonDecoder.number()) }, 'User');userDecoder.decode({name: 'John'}); // Ok<User>userDecoder.decode({name: 'John', age: 30}); // Ok<User> Copy
interface User { name: string; age?: number;}const userDecoder = JsonDecoder.object<User>( { name: JsonDecoder.string(), age: JsonDecoder.optional(JsonDecoder.number()) }, 'User');userDecoder.decode({name: 'John'}); // Ok<User>userDecoder.decode({name: 'John', age: 30}); // Ok<User>
Decoder that makes a field optional.