diff --git a/src/datatypes/set.ts b/src/datatypes/set.ts index 880e15e6..686ae795 100644 --- a/src/datatypes/set.ts +++ b/src/datatypes/set.ts @@ -505,9 +505,14 @@ export class Set implements Instance { if (!this.contains(value)) return this; const keyFn = this.keyFn; const key = keyFn(value); + + const newElements = this.elements.filter(element => keyFn(element) !== key); + return new Set({ - setType: this.setType, // There must be a set type since at least the value is there - elements: this.elements.filter(element => keyFn(element) !== key), + // In the case where we removed a string and all that's left is null, we need + // to change the setType accordingly + setType: getValueType(newElements.length ? newElements[0] : null), + elements: newElements, }); } diff --git a/test/datatypes/set.mocha.js b/test/datatypes/set.mocha.js index 0059ee6b..45acfda5 100644 --- a/test/datatypes/set.mocha.js +++ b/test/datatypes/set.mocha.js @@ -291,6 +291,11 @@ describe('Set', () => { setType: 'STRING', elements: ['A'], }); + + expect(Set.fromJS([null, 'A']).remove('A').toJS()).to.deep.equal({ + setType: 'NULL', + elements: [null], + }); }); });