The general lesson transfers well beyond this ecosystem: whenever the editor and the build disagree, believe the build.
The same split exists in almost every toolchain. The editor's analyser is a convenience layer that approximates the build, and there is a mechanism somewhere to feed it the real thing — a compilation database, a generated configuration file, a project index.
Worth learning what that mechanism is for whatever you work in. It converts a permanent low-grade annoyance into a solved problem, and it also fixes autocomplete and go-to-definition, which are the things you actually lose.