In some old QA, I found a couple of code such as
how to extend Array in typescript
Extend native JavaScript array
I am investigating how it behaves under TypeScript.
interface Array<T> {
"foo": Function;
["foo"]: Function;
}
Object.defineProperty(Array.prototype, "foo", {
value: function <T>(this, R: T) {
return (console.log(R));
}
});
[].foo("test"); // test
[]["foo"]("test"); //test
Basically, the code works, The TypeScript Playground
However, for some reason, in VSCode, TypeScript produces errors
At least I tried to type the Array property.
"suppressImplicitAnyIndexErrors": true
in tsconfig.json surely suppresses these errors, but I want to know how to make it work without this flag.
Any idea? Thanks.