TypeError: 'set' on proxy: trap returned falsish for property

See original GitHub issue

Hello awesome polly! Got an error not sure if it is me but it only happens when I use strict;. I am not adding a new path just editing existing path. If it is a bug lets see if we can fix it. If it is me slap me in the face but tell me what I am doing wrong please.

error: TypeError: 'set' on proxy: trap returned falsish for property 'port'

Example

'use strict'; // this makes the error throw

function ObserveObject(object, callback) {
    function createProxy(prefix, object) {
        return new Proxy(object, {
            set: function(target, property, value) {
                target[property] = value;
                callback(prefix + property, value);
            },
            get: function(target, property) {
                var value = target[property];

                if (isObject(value)) return createProxy(prefix + property + '.', value); 
                else return value; 
            }
        });
    }

    return createProxy('', object);
}

function isObject(value) {
    if (value === null || value === undefined) return false;
    else return value.constructor === Object;
}

var o = {
    hello: 'blue',
    app: {
        env: {
            port: 7777,
            la: 1
        }
    },
    more: 'stuff'
};

var m = ObserveObject (o, function(path, value) {
    console.log(path);
    console.log(value);
});

m.app.env.port = 8888;
console.log(m);

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:14
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

70reactions
xeaonecommented, Aug 16, 2016

Oops…

I think I figured it out.

Link: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/handler/set

"Return value

The set method should return a boolean value. Return true to indicate that assignment succeeded. If the set method returns false, and the assignment happened in strict-mode code, a TypeError will be thrown."

Should return true in the set method.

This is pretty weird though can anyone explain why?

8reactions
mutuadavid93commented, Feb 24, 2018
// NOTE: When Intercepting Sets using Proxy, it throws an Error in "use strict"
// mode, due to polyfills. Babel on it's own can transpile it without an error.
//
// Solution: Inside the set function return true and you good.
//
// i.e.
// var yourSetProxy = new Proxy(targetObject, {
//     set : function (target, property, value) {
//
//          //    Your logic here.
//
//         return true;
//      }
// });
Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught TypeError: 'set' on proxy: trap returned falsish for ...
I got the error (not exactly the same) but was able to replicate. Seems like you cannot set a value directly to the...
Read more >
Vue3: Uncaught TypeError: 'set' on proxy: trap returned falsish ...
I got an error message: Uncaught TypeError: 'set' on proxy: trap returned falsish for property 'NewTodo'. That error appear when im trying ...
Read more >
Getting Started with Modern JavaScript — Proxy - Michael Karén
Uncaught TypeError: 'set' on proxy: trap returned falsish for property 'age'. In addition to intercepting reads and modifications to properties, Proxy can ...
Read more >
TypeError: 'deleteProperty' on proxy: trap returned falsish for ...
I am aware that I may not have fully understood the way transactions are set up, but I found relatively little documentation or...
Read more >
Uncaught TypeError: 'set' on proxy: trap returned falsish for ...
Uncaught TypeError: 'set' on proxy: trap returned falsish for property Name – salesforce lightning web component.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found