Experiencing the same issue editing a typescript file with Visual Studio 2022 version 17.12.1. Found the issue to be related to the GitHub Copilot feature. I was able to stop the issue occurring by clicking GitHub Copilot, shown in the top-right corner of the editor, selecting Settings, then disabling Enable Copilot Completions.
I could not find any other condition that causes this issue. It seems to happen after some time developing when Enable Copilot Completions is enabled.