Ad
  • Custom User Avatar
      it('Handles multiple reassignments', () => {
        const typed = typedObject({ a: Array, b: String, c: Set });
        const length = Object.keys(typed).length;
        
        Object.keys(typed).forEach((key) => {
          for (let i = 0; i <= length; i++) {
            typed[key] = i;
          }
        });
        
        assert.deepEqual(typed.a, [length]);
        assert.deepEqual(typed.b, `${length}`);
        assert.deepEqual(typed.c, new Set([length]))
      });
    

    This test in the test fixture assumes that every key is already set in the typed object before any assignment, which is different from the default behaviour of object (obviously, keys that are not set yet will not appear in Object.keys). This behaviour is not mentioned anywhere, and probably should be changed.

  • Custom User Avatar

    a = b should return a ( with its new value ) in JS. The reference solution doesn't seem to do this and I haven't checked if this is tested. Existing programs sometimes rely on this; it is not good practice to return undefined for this expression even if the side effect is handled correctly.