diff --git a/index.ts b/index.ts index 34d0bb2..1b27db2 100644 --- a/index.ts +++ b/index.ts @@ -128,7 +128,7 @@ export const struct = { const fields = {}; Object.keys(json).forEach(key => { // If value is undefined, do not encode it. - if (!json[key]) return; + if (typeof json[key] === 'undefined') return; fields[key] = value.encode(json[key]); }); return {fields}; diff --git a/test.ts b/test.ts index 88bd9e7..b414cbf 100644 --- a/test.ts +++ b/test.ts @@ -5,12 +5,14 @@ const arr = [null, 10]; const obj = { foo: 'bar', - yes: true + no: false, + nil: null }; const objWithUndefined = { foo: 'bar', - yes: true, + no: false, + nil: null, isUndefined: undefined }; @@ -30,9 +32,13 @@ const structValue = { kind: 'stringValue', stringValue: 'bar' }, - yes: { + no: { kind: 'boolValue', - boolValue: true + boolValue: false + }, + nil: { + kind: 'nullValue', + nullValue: 0 } } };