You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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:
import*asngRouterfrom"angular2/router";import*asprojectAfrom"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.
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.
The text was updated successfully, but these errors were encountered:
Given this folder hierarchy, it is possible at runtime that you have two different versions of the angular2. I am guessing you have some post build step that combines the output in one directory, and reference angular2 through a CDN perhaps, but that is not obvious to the compiler.
The only thing it sees is two classes that you are trying to pass one for the other, and they have the same shape, but at least one of them have a private/protected member, and that is deemed un-safe.
options, 1. your first workaround would be one option, 2. use "paths", assuming that my statements earlier about a post-build step is accurate. you can define something like:
"compilerOptions":{"paths": {// always resolve angular2 imports to `projectA/node_modules/angular2`"angular2/*": ["projectA/node_modules/angular2/*"]}}
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.
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:
On Project B, we have:
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.
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.
The text was updated successfully, but these errors were encountered: