The property path to follow. The first name is the outer-most field
The decoder to run on that field
When you want to access the name
field in an object like this
{
"data": {
"outer": {
"inner": {
"name": "Kobe Bryant",
},
},
},
}
you would have to chain quite a few field decoders, which is annoying.
const decoder = Decode.field(
'data',
Decode.field(
'outer',
Decode.field(
'inner',
Decode.field(
'name',
Decode.string,
),
),
),
);
decode(decoder, raw) === 'Kobe Bryant'
Decode.at allows us to be more concise.
const short = Decode.at(['data', 'outer', 'inner', 'name'], Decode.string);
decode(short, raw) === 'Kobe Bryant'
Generated using TypeDoc
It's basically the same as Decode.field, but makes it easier to define deep property paths. Instead of
Decode.field('outer', Decode.field('inner', Decode.string))
you can useDecode.at(['outer', 'inner'], Decode.string)