Property 'replaceAll' does not exist on type 'string'

behroozbc picture behroozbc · Aug 27, 2020 · Viewed 17.5k times · Source

I want to use replaceAll in typescript and angular 10.

But I get this error: Property 'replaceAll' does not exist on type 'string'.

This is my code:

let date="1399/06/08"
console.log(date.replaceAll('/', '_'))

Output: 13990608

How can fix my typescript to show me this function?

Answer

strdr4605 picture strdr4605 · Aug 27, 2020

You may solve the problem using RegExp and global flag

"1399/06/08".replace(/\//g, "_") // "1399_06_08"