A decoder that accepts either the decoded value or null
interface User {
name: string;
age: number | null;
}
const userDecoder = JsonDecoder.object<User>(
{
name: JsonDecoder.string,
age: JsonDecoder.nullable(JsonDecoder.number)
},
'User'
);
userDecoder.decode({name: 'John', age: null}); // Ok<User>
userDecoder.decode({name: 'John', age: 30}); // Ok<User>
Decoder that accepts null values.