Despite searching through various stack overflow responses, I haven't been able to resolve my error. I've attempted the following:
A B
Below is my TypeScript code snippet:
interface Array<T> {
asyncForEach(callback: CallableFunction): void;
}
Array.prototype.asyncForEach = async function (callback: CallableFunction) {
// this represents our array
for (let index = 0; index < this.length; index++) {
// We call the callback for each entry
await callback(this[index], index, this);
}
};
(async () => {
const buttons: string[] = [things.methButtonId, things.cashButtonId];
buttons.asyncForEach(async (button) => {
for (let i = 0; i < 1000; i++) {
//do something
}
})
});
Upon building, I encountered the following errors:
src/index.ts:13:17 - error TS2339: Property 'asyncForEach' does not exist on type 'any[]'.
13 Array.prototype.asyncForEach = async function (callback: CallableFunction) {
src/index.ts:39:11 - error TS2339: Property 'asyncForEach' does not exist on type 'string[]'.
39 buttons.asyncForEach(async (button) => {
Additionally, Visual Studio Code displayed the following error message:
Property 'asyncForEach' does not exist on type 'any[]'.ts(2339)
Provided below is my configuration file:
{
"compilerOptions": {
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
...
}, "include": ["./src/*.ts", "src/index.js"]
}
I would greatly appreciate any assistance with resolving this issue.