I'm trying to compile my ts code with the target ES2020 as my node version is v14.17.3, according to the following tsconfig:
{
"compilerOptions": {
"target": "es2020",
"lib": ["ESNext.String"],
"module": "commonjs",
"allowJs": true,
"outDir": "./build",
"esModuleInterop": true
}
}
As String.prototype.replaceAll
is not supported in node v14.17.3 I'm getting error when running the code below, probably because the compiler is not replacing replaceAll
with a valid expression in the target ES2020:
const text = "my text"
const newText = text.replaceAll(' ', '-')
console.log(newText)
TypeError: text.replaceAll is not a function
Shouldn't Typescript compiler convert text.replaceAll(' ', '-') to a valid expression in the target ES2020?