有效数组的 Typescript forEach/Map 问题

Typescript forEach/Map issue with a valid array

我正在检查我的代码,突然出现了一个奇怪的 forEach/map 问题,即使用 TypeScript 的有效数组。代码如下

我用 forEach 和 map 都试过了,但还是不行。

执行时出错:

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"]
}

感谢您阅读本帖并尝试提供帮助!

错误在第 39:19 行,所以问题出在这段代码中:

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

您需要检查 command 是否符合您的预期。