I hit a similar problem in an application that was performing non-unicode-aware string operations on user-submitted text in a typescript codebase. The data couldn't be processed by an external service that was expecting valid Unicode. My fix was using
toWellFormed:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...