I would like to try some things around Proxies, but i struggle to get the simplest form running.
I have the following code
const myObj = {
x: 'Hello',
};
const p = new Proxy(myObj, {
get: (target, key) => {
return key in target ? target[key] + ' World!' : 'nope';
},
});
console.log(p.x);
And i get the following error, but i have no clue why and how to solve it:
index.ts:7:28 - error TS7053: Element implicitly has an 'any' type because expression of type 'string | number | symbol' can't be used to index type '{ x: string; }'.
No index signature with a parameter of type 'string' was found on type '{ x: string; }'.
7 return key in target ? target[key] + ' World!' : 'nope';
~~~~~~~~~~~
Found 1 error.
I think TS should be able to infer everything. What do i miss here?