EN
TypeScript - property 'replaceall' does not exist on type 'string'
1 answers
0 points
I want to use replaceAll
method in TypeScript under Node.js and I can't fix the following error. How can I fix it?
Error:
xxxxxxxxxx
1
TypeError: text.replaceAll is not a function
My code:
xxxxxxxxxx
1
let text: string = 'a xxx b xxx c';
2
3
const letter = 'x';
4
const replacement = 'y';
5
6
text = text.replaceAll(letter, replacement);
1 answer
0 points
Try to add "ES2021.String"
in your tsconfig.json file under compilerOptions
-> lib
.
Example:
xxxxxxxxxx
1
{
2
"compilerOptions": {
3
// ...
4
"lib": ["ES2021.String"]
5
},
6
// ...
7
}
8
0 commentsShow commentsAdd comment