I was just looking for how to deal with something similar. I work on a lot of WordPress sites, so I wind up with some global variables that don't have sane type hints. For example, I get a $data variable that's type-hinted as str|int, but it contains an array -- so I get warnings about it.
Is there some way to declare/override the type of a global variable? Something like TypeScript's "as" keyword?