I understand how a type inference algorithm infers types within a single file by building on already inferred types and identified constraints (for example, in the Hindley-Milner type system).
I wonder how this process works / is implemented for languages where some links are imported from other files. I couldn't find any useful information anywhere else, so I thought I'd just try my luck here.
Obviously, the trivial approach would be to leave the imported binding typeless (for example, substitute a type variable) and continue adding constraints. Then, when the actual definition of the link is in the other file, it is verified that the constraints and the actual type can be unified.
This approach has the main drawback that it basically discards all type information regarding a link that may be present where it is defined.
Starting with that first approach, one could start by identifying an optimal order of file analysis. In the event that there are no circular dependencies, this additional step would solve the problem. But in many cases there are circular dependencies.
In TypeScript, for example (afaik), circular dependencies are allowed without loss of type information.
How is this problem generally handled in type inference algorithms?
Are there resources / documents that describe this problem?