Having an object and the desire to listen for changes in order to execute certain actions, my initial approach in ES6 would have been:
let members = {};
let targetProxy = new Proxy(members, {
set: function (members, key, value) {
console.log(key + " set to " + value);
members[key] = value;
return true;
}
});
After converting to TypeScript:
const members = {};
let targetProxy: any = new Proxy(members, {
set: function (members: any, key: string, value: string) {
console.log(`${key} set to ${value}`);
members[key] = value;
return true;
}
});
However, encountering an error message from the linter:
[ts] Cannot find name 'Proxy'.
The terminal displays the following output:
https://i.sstatic.net/FwkzD.png
Despite conducting extensive research, I am unable to troubleshoot the issue.
In an attempt to resolve it, I modified my module parameter to ES6 instead of commonjs, but no changes were observed. Full output can be seen below:
https://i.sstatic.net/2REIG.png
Furthermore, here is a snippet from my package.json configuration:
{
"compilerOptions": {
"module": "ES6",
"moduleResolution": "node",
"noImplicitAny": true,
"sourceMap": true,
"outDir": "dist",
"baseUrl": ".",
"paths": {
"*": ["node_modules/*"]
}
},
"include": [
"src/**/*"
]
}