Home > Net >  Typescript forEach/Map issue with a valid array
Typescript forEach/Map issue with a valid array

Time:01-21

I was going through my code and suddenly a weird forEach/map Issue came up with a valid Array using TypeScript. The code is as follows

The Code

I tried this with both forEach and map and it was still not working.

Error while execution: The Error

package.json

{
  "name": "merk-development",
  "version": "1.0.0",
  "description": "A bot made by daysling for merk.",
  "main": "dist/index.js",
  "scripts": {
    "start": "ts-node src/index.ts",
    "build": "rm -rf dist && tsc",
    "typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js"
  },
  "author": "daysling",
  "license": "Copyright",
  "dependencies": {
    "@types/dotenv": "^8.2.0",
    "discord-ghost-transcript": "^1.0.1",
    "discord.js": "^13.6.0",
    "dotenv": "^14.0.0",
    "mojang": "^2.2.2",
    "mysql": "^2.14.1",
    "redis": "^4.0.2",
    "reflect-metadata": "^0.1.10",
    "typeorm": "0.2.41"
  },
  "devDependencies": {
    "@types/node": "^8.10.66",
    "ts-node": "10.4.0",
    "typescript": "4.5.4"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "lib": ["ES2020", "ES2021"],
    "target": "ES2020",
    "strict": true,
    "module": "CommonJS",
    "declaration": false,
    "noImplicitAny": false,
    "strictNullChecks": false,
    "inlineSourceMap": true,
    "outDir": "./dist",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowJs": true
  },
  "include": ["src"]
}

Thanks for reading this thread and trying to help out!

CodePudding user response:

Error is at line 39:19, so the problem is in this code:

// command.alliases is undefined
command.alliases.map(/* ... */)

You need to check whether command is what you are expecting it to be.

  •  Tags:  
  • Related