I am unable to use flatmap with node or ts-node despite previously being able to in my code. I am not sure what changed but I am getting this error 'TypeError: [x].flatMap is not a function'
flatMap() should be a function because I explicitly make x an array (this code was working before no problems).
here is my tsconfig.json
{
"compilerOptions": {
"moduleResolution": "node",
"target": "es2020",
"esModuleInterop": true,
"sourceMap": true,
"strictNullChecks": true,
"outDir": "out",
//"strictBindCallApply": true,
//"strict": true
}
}
and here is my lancher
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/src/main.ts",
"outFiles": ["${workspaceFolder}/out/**/*.js"],
"preLaunchTask": "npm: build",
"runtimeArgs": ["-r", "esm"],
"stopOnEntry": true,
"console": "integratedTerminal",
},
{
"type": "node",
"request": "launch",
"name": "Mocha Tests",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"-u",
"tdd",
"--timeout",
"999999",
"--colors",
"--require",
"esm",
"--require",
"ts-node/register",
"--project",
"${workspaceFolder}/tsconfig.json",
"${workspaceFolder}/**/*spec.ts"
],
"console": "integratedTerminal",
"stopOnEntry": false,
}
]
}
and the flatmap call in question
(x: discord.Message | discord.Message[] | null): (discord.Message | null)[] => [x].flatMap(
// @ts-ignore
(t: discord.Message | discord.Message[] | null): (discord.Message | discord.Message[] | null) => t
)
another example that does not work:
const test = [1,3,4,[5,4,2]].flatMap(x => x);
TypeError: [1,3,4,[5,4,2]].flatMap is not a function
Neither ts-node/register or ts-node seems to respect "target": "es2020"
anymore and I am not sure what exactly changed. VScode does have context for intellesense for flatMap. Can anyone explain to me why it is not working anymore?
The problem was I had a conflict in the version number of node after an install of a program. I have stopped using the snap package of node and started using nvm.