-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Description
Hi,
I'm having trouble calling a function of another module that receives an argument with a type from a third distinct module. I hope the explanation bellow helps you get a sense of the problem.
TypeScript Version:
1.8.9
We have the following folder structure. ProjectB depends on ProjectA. Both depend on Angular2.
| -- Solution
| -- projectA
| -- node_modules
| -- angular2
| -- projectB
| -- node_modules
| -- angular2
| -- projectA
Note: We use node as resolution strategy. angular2 folder is, in both cases, a symlink and both point to the same concrete folder, so the files inside them are exactly the same.
Code
On Project A, we have a class that has something like this:
public navigateByAction(router: ngRouter.Router): Promise<void>
On Project B, we have:
import * as ngRouter from "angular2/router";
import * as projectA from "projectA/main";
...
public router: ngRouter.Router;
....
// Eventually we call a method from projectA.
projectA.navigateByAction(this.router);
Expected behavior:
No TS Compiler error.
Actual behavior:
Argument of type 'Router' is not assignable to parameter of type 'Router'.
Types have separate declarations of a private property '_rootComponent'.
Workarounds
Workaround 1
If I change the structure of the project to something like the following it works fine.
This is not the way we want to move forward because each module should have it's own dependencies and not rely on a parent for dependency resolution.
| -- Solution
| -- node_modules
| -- angular2
| -- projectA
| -- projectB
| -- node_modules
| -- projectA
Workaround 2
Casting to any before calling the function will of course stop the error on the compiler. Definitely not the solution we are looking for in the long term.