Languages

TypeScript - property 'replaceall' does not exist on type 'string'

0 points
Asked by:
Richard-Bevan
413

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:

TypeError: text.replaceAll is not a function

My code:

let text: string = 'a xxx b xxx c';

const letter = 'x';
const replacement = 'y';

text = text.replaceAll(letter, replacement);
1 answer
0 points
Answered by:
Richard-Bevan
413

Try to add "ES2021.String" in your tsconfig.json file under compilerOptions -> lib.

Example:

{
    "compilerOptions": {
        // ...
        "lib": ["ES2021.String"]
    },
    // ...
}
0 comments Add comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join