I've recently worked on something similar, which uses dynamic analysis to be able to collect type informations and many other data which is only available at runtime.
Runtime type checking: https://maierfelix.github.io/Iroh/examples/type-checking/
JavaScript -> Flow conversion: https://maierfelix.github.io/Iroh/examples/auto-flow-types/
It's also possible to turn the runtime control-flow of running JavaScript into a playable game: https://maierfelix.github.io/src2game/