我在我的代码中使用带有ESNEXT
(截至 2021 年)的 Typescript replaceAll
,因为它比使用正则表达式更清晰。
我正在编译es5
,但在dist
文件夹中,在经过转换的 js 代码中,replaceAll
保持原样并且出现TypeError: replaceAll is not a function
错误。
我认为 Typescript 会以与 es5 一起使用的方式将其转换为 es5。为什么不这样做?我该如何解决这个问题?
我的 TS 配置是:
{
"compilerOptions": {
"strict": true,
"target": "es5",
"lib": [
"ES2021"
],
"sourceMap": true,
"outDir": "../dist/server",
"baseUrl": ".",
"resolveJsonModule": true,
"downlevelIteration": true,
"paths": {
"@/*": [
"./*"
]
}
}
}