We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f7f11bf commit b07afcdCopy full SHA for b07afcd
index.ts
@@ -175,7 +175,7 @@ export const struct = {
175
* @param {Struct} struct the protobuf struct.
176
* @returns {Object.<string, *>}
177
*/
178
- decode({fields}: Struct): JsonObject {
+ decode({fields = {}}: Struct): JsonObject {
179
const json = {};
180
Object.keys(fields).forEach(key => {
181
json[key] = value.decode(fields[key]);
test.ts
@@ -214,3 +214,8 @@ test('struct.decode', t => {
214
const actual = struct.decode(structValue);
215
t.deepEqual(actual, obj);
216
});
217
+
218
+test('struct.decode - undefined fields', t => {
219
+ const actual = struct.decode({});
220
+ t.deepEqual(actual, {});
221
+});
0 commit comments